I'm looking in this for quite a while. but i cant figure it out. here is my code Code (CSharp): using UnityEngine; using System.Collections; public class pylon : MonoBehaviour { public bool toggle; public float Y; public float timer; public static bool nogeenkeerschieten = false; bool strikecheck = false; public float timer1; public bool timerafloop = false; // Use this for initialization void Start () { timer = 5; timer1 = 6; } // Update is called once per frame void Update() { Y = transform.rotation.y; if (transform.rotation.y > 0.1 || transform.rotation.y < -0.1) { timer -= 1 * Time.deltaTime; if (timer <= 0) { Destroy(gameObject); Spawner.pylonnen -= 1; strikecheck = true; } } /* if (toggle == false) { Spawner.pylonnen -= 1; toggle = true; } */ /*} if (toggle == true) { timer -= 1 * Time.deltaTime; if (timer <= 0) { //nogeenkeerschieten = true; Destroy(gameObject); strikecheck = true; */ /////////////////////////////////// if (strikecheck == true) { timer1 -= 1 * Time.deltaTime; if (timer1 <=0) { //timer neit gelijk doen if (Spawner.pylonnen == 0) { Debug.Log("strike"); //GUI.Box(new Rect(Screen.width - 100, 0, 100, 50), "STRIKE!!!"); } else if (Spawner.pylonnen > 0) { Debug.Log("2e trow"); nogeenkeerschieten = true; } } } } } but my problem is. That where is says that strikecheck needs to go to true; and then where strikecheck needs to be true. then there needs to be a timer counting down from 6 to 0 when that is happened it should calculate if you have a strike or not. But for some reason timer1 doesnt go down to 0 so it stays at 6; can somebody help?
It seems like your script is looking for the rotation y axis in euler, but you're accessing the quaternion y axis, they're very different. However there is a solution: instead of transform.rotation.y, do: transform.rotation.eulerAngles.y Hope this helps!
no that part works. when the rotation y is greater then 0.1 and below - 0.1 it destroys the object. and also sets the spawner.pylonnen -=1. it also sets strikecheck to true.so the upper part of the code works. but the bottom part where i do Code (CSharp): if (strikecheck == true) { timer1 -= 1 * Time.deltaTime; if (timer1 <=0) { //timer neit gelijk doen if (Spawner.pylonnen == 0) { Debug.Log("strike"); //GUI.Box(new Rect(Screen.width - 100, 0, 100, 50), "STRIKE!!!"); } else if (Spawner.pylonnen > 0) { Debug.Log("2e trow"); nogeenkeerschieten = true; } doesnt work the timer1 stays at 6 and is not counting down
So, you destroy the gameObject, then wonder why the code stops? Not even sure how youre viewing the object, since it should be disappearing from the hierarchy.