Question by
dragon081223 · Feb 17, 2019 at 10:27 AM ·
c#conditional
Trying to change state of object when Timer reaches zero
public class Timer : MonoBehaviour { public static float time; public static float startTime = 5; public Text countdownText;
// Start is called before the first frame update
void Start()
{
time = startTime;
StartCoroutine(LoseTime());
Time.timeScale = 1;
countdownText.text = time.ToString();
}
// Update is called once per frame
void Update()
{
countdownText.text = time.ToString(); //Showing the Score on the Canvas
print(time);
}
//Simple Coroutine
IEnumerator LoseTime()
{
while (true)
{
yield return new WaitForSeconds(1);
time--;
}
}
}
public class BlockBehavior : MonoBehaviour { public static int floorPosition = 1;
private GridService gridService = new GridService();
private bool isDrop;
private bool isSet;
private GameObject player;
public float fallSpeed;
private float fallTime = 0;
int stopHeight;
// Start is called before the first frame update
void Start()
{
isSet = false;
isDrop = false;
player = GameObject.Find("Player");
}
// Update is called once per frame
void Update()
{
BlockDrop();
if (Timer.time <= 0)
{
print("fall");
isDrop = true;
gameObject.name = "FallingBlock";
Timer.time = Timer.startTime;
}
else
{
if (Input.GetKeyDown(KeyCode.Space))
{
isDrop = true;
gameObject.name = "FallingBlock";
Timer.time = Timer.startTime;
}
}
}
Comment
some like:
//Simple Coroutine
IEnumerator LoseTime()
{
while (0 < time)
{
yield return new WaitForSeconds(1);
time--;
}
//Change state here, (coroutine ends after that, there are no more WaitForSeconds(1);)
}
?
Your answer
Follow this Question
Related Questions
Why do nested if statements act differently than the && operator? 1 Answer
Can't access methods from class 1 Answer
OnTriggerEnter 1 Answer
Running 'helper' programs, 0 Answers
Rotation Changing Z-Coordinate Value 0 Answers