Respawn Ball to specific spawnpoint after death
Hey guys and girls. I've got this roll a ball game and i made a killCube that destroys the player Ball when it touches it. According to my script it respawns the ball at Vector3.zero but i want it to respawn on an empty gameObject to my choosing.
this is my current KillCube script:
public class KillCube : MonoBehaviour {
void OnCollisionEnter(Collision player)
{
if (player.gameObject.name == "player") {
player.gameObject.SetActive (false);
}
}
}
and this is my current respawn script:
public class Respawn : MonoBehaviour {
public GameObject player;
public Transform spawnpoint;
void Start() {
spawnpoint = player.transform;
}
void Update()
{
if (player.gameObject.activeInHierarchy == false)
{
player.transform.position = Vector3.zero;
player.SetActive (true);
}
}
}
it should be possible to spawn the ball back at the empty gameobject "spawnpoint" right? i just can't figure out how to do that.
Answer by JvanOpstal · Oct 02, 2017 at 02:32 PM
If you replace the line "player.transform.position = Vector3.zero" with player.transform.position = spawnPoint.position you're ball should respawn at your spawnpoint.
Your answer
Follow this Question
Related Questions
i want to find object x position value at run time please help me 0 Answers
Spawn Procedural Planet at parent's position 0 Answers
Spawn Object on Set Score 0 Answers
X coordinates isn't the same on my gameobjects when on same position. 1 Answer
How do you thrust an object to another object's position? 0 Answers