I am looking to rotate an image on my canvas via its Rect Transform value. I have tried this on all of the different Canvas types and it still does not rotate. Your thoughts? Thanks guys!
var timeCounter : int = 0;
var x : float;
var y : float;
var z : float;
function Update()
{
timeCounter += Time.deltaTime;
x = Mathf.Cos(timeCounter);
y = Mathf.Sin(timeCounter);
z = 0;
GetComponent.<RectTransform>().tranform.rotation = Quaternion.Euler(x,y,z);
print("X: " + x + "Y: " + y + "Z: " + z);
}
As a note, this code shouldn’t compile, which means you should have been able to see an error in the Unity console (check the very bottom of the window). This is your first place to look for problems, and when you come here, always paste in any errors you have along with the code!
You can press F5 in the monodevelop to see if the code compiles… Also to rotate (simple) you can use this method
this.transform.Rotate(Vector3.right, Mathf.Deg2Rad * rotationY); // This is for right left rotation which im using with mouse drag… if you change Vector3.right to Vector3.up then you will have upwards rotation too