-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTimer.cs
69 lines (62 loc) · 2.07 KB
/
Timer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Timer : MonoBehaviour
{
[Header("Timer")]
public float countDownTimer = 5f;
[Header("Things to stop")]
public PlayerCarController playerCarController;
public PlayerCarController playerCarController1;
public PlayerCarController playerCarController2;
public OpponentCar opponentCar;
public OpponentCar opponentCar1;
public OpponentCar opponentCar2;
public OpponentCar opponentCar3;
public OpponentCar opponentCar4;
public Text countDownText;
// Start is called before the first frame update
void Start()
{
StartCoroutine(TimeCount());
}
// Update is called once per frame
void Update()
{
if (countDownTimer > 1)
{
playerCarController.accelerationForce = 0f;
playerCarController1.accelerationForce = 0f;
playerCarController2.accelerationForce = 0f;
opponentCar.movingSpeed = 0f;
opponentCar1.movingSpeed = 0f;
opponentCar2.movingSpeed = 0f;
opponentCar3.movingSpeed = 0f;
opponentCar4.movingSpeed = 0f;
}
else if (countDownTimer == 0)
{
playerCarController.accelerationForce = 300f;
playerCarController1.accelerationForce = 300f;
playerCarController2.accelerationForce = 300f;
opponentCar.movingSpeed = 12f;
opponentCar1.movingSpeed = 13f;
opponentCar2.movingSpeed = 14f;
opponentCar3.movingSpeed = 9f;
opponentCar4.movingSpeed = 8f;
}
}
IEnumerator TimeCount()
{
while (countDownTimer > 0)
{
countDownText.text = countDownTimer.ToString();
yield return new WaitForSeconds(1f);
countDownTimer--;
}
countDownText.text = "60";
yield return new WaitForSeconds(1f);
countDownText.gameObject.SetActive(false);
}
}