Hi, I have 2 scripts one for spawn second for object collision. I want when every time object collision happen level int increase and every time level int increase my coroutine restart
public class LevelManager : MonoBehaviour
{
public static LevelManager Instance;
public int Stage = 1;
void Start()
{
StartCoroutine(StartTime());
}
void Update()
{
Levels();
}
void Levels()
{
switch (Stage)
{
case 5:
CannonSpeed = 24f;
break;
case 4:
CannonSpeed = 12f;
break;
case 3:
CannonSpeed = 6f;
break;
case 2:
CannonSpeed = 3f;
break;
case 1:
CannonSpeed = 1.5f;
break;
}
}
public IEnumerator StartStage()
{
GameObject Bullet = PoolManager.Instance.GetPooledObject();
Bullet.transform.position = Cannon.transform.position;
Bullet.transform.rotation = Cannon.transform.rotation;
Bullet.SetActive(true);
yield return null;
}
public IEnumerator StartTime()
{
yield return new WaitForSeconds(Delay);
StartCoroutine(StartStage());
}
//Second Script
public class Bullet : MonoBehaviour
{
void OnTriggerEnter(Collider hit)
{
if(hit.gameObject.tag == "Target")
{
gameObject.SetActive(false);
gameObject.GetComponent<Rigidbody>().velocity = Vector3.zero;
LevelManager.Instance.Stage++;
}else if(hit.gameObject.tag == "Death")
{
gameObject.SetActive(false);
gameObject.GetComponent<Rigidbody>().velocity = Vector3.zero;
LevelManager.Instance.GameOver();
}
}
}