Hi, I have a small project with genre fishing. Have a problem on detect rotation.
I have a GUI texture like a reel that can be rotated.
How can i make the length decrease based on each 15 degree the reel rotated?
Here is my Rotate code in C#:
public class Rotate : MonoBehaviour {
public Texture2D texture = null;
public Vector2 size = new Vector2(0, 0);
private float angle = 0;
private Vector2 pos = new Vector2(0, 0);
private Rect rect;
private Vector2 pivot;
public static bool rotating = false;
public static bool rotating2 = false;
private float initialMouseAngle;
static float speed = 0.1f;
float factor = Screen.width/800;
void Start() {
UpdateSettings();
}
void UpdateSettings() {
pos = new Vector2(Screen.width-factor*700,Screen.height-factor*320+200);
rect = new Rect(pos.x - size.x * 0.5f, pos.y - size.y * 0.5f, 150, 150);
//Debug.Log ("Rect="+rect);
pivot = new Vector2(rect.xMin + rect.width * 0.5f, rect.yMin + rect.height * 0.5f);
//Debug.Log ("Pivot ="+pivot);
}
void OnGUI() {
if (Application.isEditor){
UpdateSettings();
}
Vector2 guiMouse = Input.mousePosition;
guiMouse.y = Screen.height - guiMouse.y;
if (Input.GetMouseButtonDown(0) && rect.Contains(guiMouse)) {
Vector2 v2T = ((Vector2)guiMouse - pivot);
initialMouseAngle = Mathf.Atan2(v2T.y, v2T.x) - angle * Mathf.Deg2Rad;
rotating = true;
}
else if (Input.GetMouseButton(0) && rotating) {
Vector2 v2T = ((Vector2)guiMouse - pivot);
angle = (Mathf.Atan2 (v2T.y, v2T.x) - initialMouseAngle) * Mathf.Rad2Deg;
//GetComponent<Length>().Jarak(speed);
rotating2 = true;
rect.ToString();
}
else if (Input.GetMouseButtonUp(0)) {
rotating = false;
rotating2 = false;
}
Matrix4x4 matrixBackup = GUI.matrix;
GUIUtility.RotateAroundPivot(angle, pivot);
if(FishingGUI.waktu == true){
GUI.DrawTexture(rect, texture);
animation.Play("idle");
return;
}
GUI.matrix = matrixBackup;
}
}
I want to integrated with this want, so each 15 degree can decrease the length:
public class Length : MonoBehaviour {
[SerializeField]
float MaxLength = 100f;
float CurrentLength = 0f;
void Start () {
CurrentLength = MaxLength;
}
override public string ToString(){
return CurrentLength + "";
}
public void Jarak(float tarikans){
CurrentLength -= tarikans;
}
void Update(){
if(CurrentLength <= 0){
CurrentLength = 0;
}
}
}
Please anyone can help or any other solution? Thanks

There might be a way to implecate transform. into the script to make it more convinient unless c# does not use that.
– greencvbnthanks for replying, but i still do not get it. Can you give me some other clue? or maybe another solution beside detecting GUI degrees?
– iast999don't you already have the degree because you're using variables with RotateAroundPivot
– TimBorquezYou mean this? But this code just make it rotate, not explain anything about degrees. Anyone please help.. Vector2 v2T = ((Vector2)guiMouse - pivot); angle = (Mathf.Atan2 (v2T.y, v2T.x) - initialMouseAngle) * Mathf.Rad2Deg;
– iast999Maybe just grab an angle value when you start rotating. Check difference between that angle and an angle you update every frame. If it goes > or < 15 degrees make a change. If you release it at +- 6 store that and add that to your comparison next time.
– Vonni