- Home /
The question is answered, right answer was accepted
how to script a position
I have figured out how to reset the scene for my game. I started telling people about it, and they all asked the same thing I never expected: SCORING. I have an idea for a score count and how to script that, but what I don't know is how to reset all else but NOT the score. I eventually decided to set all goal detectors back to true (they are disabled when the ball enters the goal) and the positions of the 2 players and the ball back to their start positions. How exactly would I code that? This is what I have for the boundaries:
private void Update()
{
if (EndGame == true)
{
if (Input.GetKey("r"))
{
}
}
}
What would I input into this?
Answer by shadowpuppet · Apr 16, 2018 at 02:57 PM
You can have empty game objects on the field in the places you want the 2 players and the ball to be as their default ( reset) position and move them there. Just copy the transforms of the ball at his start position and paste the values into the ballStart empty gameObject. Do same with players position onto their playerStart empty gameObjects. Drag the appropriate items into their respective slots in the script
public Transform ballStart;
public Transform player1Start;
public Transform player2Start;// empty gameObjects on field for starting point markers
public GameObject ball;
public GameObject player1;
public GameObject player2;//the players and ball
private void Update()
{
if (Input.GetKeyDown(KeyCode.R) && EndGame == true)
{
ball.transform.position = ballStart.transform.position ;
player1.transform.position = player1Start.transform.position ;
player2.transform.position = player2Start.transform.position ;
}
}