Reputation: 109
I'm making a game where I have a door that rotates 90 degrees. When the door rotates I want something to happen when the transform.rotation is (0 ,0 , 30), so basically when it has rotated 30 degress on the z-axis. I've tried some stuff, but this is how i've come so far.
public GameObject door;
private void Update()
{
if(door.transform.rotation.z == 30)
{
///Do something
}
}
Like I said earlier, I want something to happen when the door has rotated 30 degrees.
Nothing happens when i use this code.
Upvotes: 0
Views: 59
Reputation: 17017
1) transform.rotation is not using degree, use eulerAngles.
2) when you want to compare float values , its never equal (approximatives values), so you could test if the value belongs to an interval (or use Mathf.Approximately, but its the same thing):
if(door.transform.eulerAngles.z > 29 && door.transform.eulerAngles.z < 31)
{
///Do something
}
Upvotes: 1
Reputation: 11
You can try output 'door.transform.rotation.z' to see what is this value. Probably, it is between 0.0 and 1.0
Upvotes: 0