Hello community,
I created this script, which should work like this : If the ball goes to collider, it will show goal canvas, wait 7 seconds and spawn players and ball back to starting positions. The problem comes after the goal, players and ball is spawned right nut after that they cannot move. Game is in 2d enviroment.
void Update()
{
if (startgoal == true)
Timer -= Time.deltaTime;
if (Timer <= 0.0f)
{
Goal.gameObject.SetActive(false);
GoalSound.Stop();
ball.transform.position = destination.position;
player1.gameObject.SetActive(true);
player2.gameObject.SetActive(true);
ball.SetActive(true);
startgoal = false;
player1.transform.position = destinationp1.position;
player2.transform.position = destinationp2.position;
}
}
void OnCollisionEnter2D(Collision2D collision)
{
Goal.gameObject.SetActive(true);
GoalSound.Play();
ball.SetActive(false);
ball.transform.position = destination.position;
Debug.Log("Goal!");
startgoal = true;
player1.gameObject.SetActive(false);
player2.gameObject.SetActive(false);
}
}
Thank you soo much