I have spent the last 4 hours trying to figure this out with no luck:
I’m trying to get the Player (the purple box) to respawn at a set point immediately after coming in contact with the enemy (the red box). What do i do?
1 Answer
1Both objects should have rigidbodies and colliders. Also the enemy should be tagged with tag “Enemy” for this to work. Then add this below code to any script (or create a new one) on your player game object. Don’t forget to assign the spawn point to the spawnPoint variable in the inspector (An empty game object would serve, feel free to change it to a Vector3 if you want to input the coordinates manually).
public Transform spawnPoint;
private void OnCollisionEnter(Collision colInfo) {
if(colInfo.collider.tag == "Enemy") transform.position = spawnPoint.position;
}
Please post your script, so that we can help you understand what you did wrong.
– corn