disable gameobject after rotation limit
Hello. I am looking for a simple script that would would pretty much say: if gameobject1's x rotation is greater then 210 but less than 330 then disable gameobject2 otherwise enable gameobject 2.
gameobject1 is my rotating cube to which gameobject2 (directional light) is parented to.
Im new to scripting so i dont know the exact format to write it in. Any help would be appreciated.
Answer by MerryAce123 · Sep 29, 2015 at 02:37 PM
Well, first thing i would recommend you to do is to store your rotation range into a variable that you can access through the inspector. Then you have to put an if block into void update which means that the game will update the if block every single frame. And you should probably store your Game Object´s rotation into a variable as well. Then the if block should ask if the objects actual rotation is in your specified range. If it is, you simply disable the object. Here is the code:
public float minRotation = 210f;
public float maxRotation = 330f;
void Update() {
float actualRotation = transform.eulerAngles.x;
if(actualRotation > minRotation && actualRotation < maxRotation){
gameObject.SetActive(false);
}
}