Hello, I want to know how I can get the rotation of an Object:
In particular I have a rectangle that rotate of 45° itself if the mouse is clicked. But I want to do something(for example: Debug.Log(You Win!)) if it is rotated of 180°.
Do you know any solution for this problem?
I’d recommend using a script on the rectangle that holds the number of times it was clicked. Since each click is 45°, then a click count of 4 would be 180°. So check for clickCount == 4 (and make sure to wrap clickCount back to 0 when it reaches 8, since that’s 360°).
Eric5h5’s solution makes the most sense given your question. As an alternate, you can check the Vector3.Dot() of two vectors. For example, if your rectangle is rotating around the ‘z’ axis, and it starts with it local ‘up’ pointing in the same direction as world ‘up’, you can check with:
if (Vector3.Dot(transform.up, Vector3.down) > 0.99) {
Debug.Log("You Win");
}
If the initial rotation is arbitrary you can do something like:
private var down : Vector3;
function Start() {
down = -transform.up;
}
function Update() {
if (Vector3.Dot(transform.up, down) > 0.99) {
Debug.Log("You Win");
}
}
private var x : float;
private var y : float;
private var z : float;
function Update()
{
x = transform.rotation.x;
y = transform.rotation.y;
z = transform.rotation.z;
if(y == 180)
{
print("You won!");
}
}