Passing Vector3 Values to RectTransform.Rotation
Hello Guys, I would like to ask a question about my script for the rotation of my 2D RectTransform object. Here is my C# Script:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class QTileViz : MonoBehaviour {
public Queuing queuing = new Queuing();
public Image[] qTiles;
public RectTransform[] rTiles;
public Sprite[] tileSprite;
ArrayList qList;
ArrayList rList;
// Use this for initialization
void Start () {
qList = queuing.queue.GetList ();
rList = queuing.queue.GetYRotations ();
}
// Update is called once per frame
public void UpdateViz () {
rList = queuing.queue.GetYRotations ();
print ("List Size:" + rList.Count);
//for (int i = 0; i < rList.Count; i++)
// print ("index " + i + ": " +rList [i]);
for (int i = 0; i < 5; i++) {
qTiles [i].sprite = tileSprite [(int)qList [i]];
print ("index " + i + ": " +rList [i]);
//rTiles [i].Rotate (0, 0, (int)rList [i]);
rTiles [i].Rotate(new Vector3 (0, 0, (int)rList [i]));
}//for
}
}
The values I'm passing to the index at my print statement
print ("index " + i + ": " +rList [i]);
is correct and I'm getting the proper numbers I should get and printed. which means my 'Queue` Implementation is correct. Here's the console output
But when I try to pass it to the RectTransform as the z
value, I'm getting wrong results for its rotation.
rTiles [i].Rotate(new Vector3 (0, 0, (int)rList [i]));
And this will be the result:
Note that the last value or the last 4th index from my queue should be for the 5th QueueTile
GameObject and the last index value from the queue is 0
and I don't even know where I got that 90.00001
and it is not from the index 0
from my queue because the z value
on the RectTransform[]
just making random numbers that is close to my types of z
which is
0, 90, 180, 270
I hope you can inspect my code and tell me what's going on or is it at Unity problem? I hope you understand. And sorry for my long question. I can't find any other way to explain this. Sorry for bad English.
TIA Cheers!
Answer by TashaSkyUp · Mar 15, 2017 at 09:26 PM
Just taking a stab here. Do the elements of in rTiles[] already have a Z rotation? The function .Rotate rotates a transform further, it does not set the rotation.
Your answer
Follow this Question
Related Questions
Torrent rotation to face an object rotating on Z axis only. Define facing axes as X 1 Answer
How do you change your z axis in a movement script. 1 Answer
How to limit only one axis rotation? c# 1 Answer
Limiting gameObjects rotation on Zaxis giving wierd results 1 Answer
How to move an object on a 2d plane forward, backward, and in a rotation about the mouse position? 0 Answers