How can I make a Player class have an origin as a property, and then a Respawn zone access that property.
Hi, I am making a game for a class which requires that I have an invisible object respawn two independently controlled players, using a Player class, to their respective original positions.
In the player class, I added this code (only the related code is shown):
private Vector3 origin;
void Start()
{
rb = GetComponent<Rigidbody> ();
}
void Update ()
{
Movement();
Jump();
}
public Vector3 Origin //The property I want to access
{
get
{
if (gameObject.tag == "Player 1")
{
return new Vector3 (7.37f, 15.041f, -10.31f);
} else
{
return new Vector3 (10f, 15.041f, -10.31f);
}
}
}
For the respawn object (respawn zone), I added this code
{
void Start()
{
Player Player1 = new Player ();
Player Player2 = new Player ();
}
void OnTriggerEnter(Collider other)
{
//If the player collides with the respawn zone, the player will respawn to his or her original position.
other.gameObject.transform.position = new Vector3 (Player1.Origin);
}
}
I understand the new Vector3(Player1.Origin) is incorrect but I can't seem to get Monodev to know I am trying to access the Origin property.
Thanks, Brandon Moss.
Your answer
Follow this Question
Related Questions
Moving and Rotating a Player Smoothly on a Rotating Planet 0 Answers
Tutorial or example for movement in 3D space? 0 Answers
What are these on my terrain and how do i get rid of them? 0 Answers
Lifes count resets with level 0 Answers
Make a 3D Object look like hes facing a point in an 2D space 0 Answers