Hello everyone,
in my GameManager.cs I was trying to do a coroutine which stops the scene, counts for 3 seconds, and starts everything in the scene.
I managed to stop game timer and stuff, but I’ve got a problem with Player not being stopped by the coroutine.
Player is managed by Player.cs. It has speed variable and some code, for example losing speed while gaining altitude.
I would like to keep that code, but stop Player from moving for 3 seconds while coroutine works, and then let him start.
This is what I tried to do in my GameManager. I get the component from other script and the speed variable. Bool ‘count’ checks if the coroutine is working. While it is, Player’s speed is meant to be 0, while it is not, speed is meant to be 90, and timer is supposed to start.
void Update()
{
GameObject plane = GameObject.Find("Player");
Player s = plane.GetComponent<Player>();
//Countdown working
if (count == true)
{
s.speed = 0f;
TimeText.text = ("0.0");
}
//Countdown finished
if (count == false)
{
s.speed = 90.0f;
//Game timer
time += Time.deltaTime;
TimeText.text = (time.ToString("f1"));
}
Timer starts flawlessly, but I can rotate the Player while coroutine is playing (which I would like to avoid), and when the Player starts moving it doesn’t preserve the code from Player.cs (losing speed while gaining altitude stuff).
All I want is stop any Player movements for 3 seconds, and then let him go with all the code in Player.cs.
How can I tackle this?