I wish to ask a query in regards to the scaling of objects to the dimensions of the display screen.
However the query just isn’t an issue that may be solved by setting the “canvas scaler” to “scale with display screen measurement.”
It is about learn how to program the code.
As proven within the image, the operate I wish to obtain is to make the hexagonal graphics change place with the participant’s working angle.
And my code has efficiently achieved this impact! Nevertheless, I bumped into an issue as a result of the worth of “rotationRadius” didn’t change and remained fastened on the beforehand set 320 f.
So when the display screen will get smaller, the hexagonal pointer will transfer away from the ruler.
When the display screen is enlarged, the hexagonal pointer will likely be within the arc ruler.
I would like the “Hexagon Indicator” to maneuver intently to the arc ruler. This hexagon should not deviate from the arc ruler below completely different display screen sizes!
However I do not understand how to do this.
Maybe I can multiply the 320 f I set by a number of the scale parameters.
However that is the issue. What’s the calculation system of this parameter?
In fact, along with multiplying the parameters, there ought to be different extra acceptable strategies, reminiscent of utilizing anchor , however I actually do not know learn how to do?
Might you please help me in rewriting the next program code?
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
utilizing UnityEngine.UI;
utilizing TMPro;
//該腳本是掛在六邊形指標上
public class Exercise_Angle : MonoBehaviour
{
[SerializeField]
Remodel rotationCenter; // 這是一個放在弧形尺標中央的空物件,作為旋轉中心
[SerializeField]
public float rotationRadius = 320f;
[SerializeField]
personal float posX, posY, angle = 0f;
[SerializeField]
float Max_Green_Angle,current_Angle;
// Max_Green_Angle是尺標刻度最大角度;current_Angle是玩家操作角度。
void Replace()
{
//讓六邊形指標可以做橢圓運動
posX = rotationCenter.place.x + Mathf.Cos(angle) * rotationRadius;
posY = rotationCenter.place.y + Mathf.Sin(angle) * rotationRadius/2 ;
rework.place = new Vector3(posX, posY, 0);
angle = 3.14f+((current_Angle/ Max_Green_Angle) * 3.14f);
if (angle >= 6.28f)
angle = 3.14f;
}
}