Unity5/C# beginner here! Need some scripting help :) <3
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?
Please post your script, so that we can help you understand what you did wrong.
Answer by SarperS · Jun 24, 2016 at 11:26 AM
Both 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;
}
Your answer
Follow this Question
Related Questions
I need help with boss design. I am new to coding so any help would be nice. 0 Answers
"Field " " is never assigned to, and will always have it's default value null" 2 Answers
How to toggle elements within a prefab in Unity 0 Answers
I need help about Basic Basketball Game 0 Answers
how to assign different Gameobject to a single variable during run time using c#? 1 Answer