- Home /
Player will not Die or Respawn
Hello. I am producing a game where I cannot get a very simple mechanic to work. Basically, in the context of my project (An overhead Bullet Hell shooter produced in 3D); A Big Yellow Cube heads downwards and if the Player Touches it, the player dies and respawns at a set point.
The Coordinates have been set for this respawn point and the Player and Enemy definitely make contact when I run it. But the player does not respawn at the designated point and instead just phases through the big yellow cube to no effect.
Here is the script that I have attatched to the big yellow cube in it's entirety:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class TriggerCollide : MonoBehaviour {
GameObject player = GameObject.FindWithTag("Player");
GameObject respawnPoint = GameObject.FindWithTag("Respawn");
// Use this for initialization
void Start () {
}
void onTriggerEnter(Collider other)
{
//When player collides with Enemy Object, Should Despawn and Respawn plyaer.
player.SetActive(false);
player.SetActive(true);
player.transform.position = respawnPoint.transform.position;
//Should Respawn the player on the "Respawn" Object.
}
}
Nothing I have done has managed to get this to work the way I want. I have no idea what to do. Please Help.
seems allenallenallen's answer is correct. If so, you should press the accept button. to encourage people like this to continue answering your future questions.
Answer by allenallenallen · Apr 20, 2017 at 09:22 PM
Capitalization matters
"OnTriggerEnter"
Not "onTriggerEnter"
TY, this has helped, I've also recieved some advice from a college associate and I have gotten the code working the way I want it.
public class TriggerCollide : $$anonymous$$onoBehaviour {
GameObject player;
GameObject respawnPoint;
// Use this for initialization
void Start () {
player = GameObject.FindWithTag("Player");
respawnPoint = GameObject.FindWithTag("Respawn");
}
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player")) //Detects if 'Other' code is of the Player Tag.
{
//When player collides with Enemy Object, Should Despawn and Respawn player.
player.SetActive(false);
player.SetActive(true);
player.transform.position = respawnPoint.transform.position;
//Should Respawn the player on the "Respawn" Object.
}
}
}
Amendment 21/04/17: The Above Code is working properly
Your answer
Follow this Question
Related Questions
Can someone help me with my player kill script? 0 Answers
How do I respawn the Player after it dies? 3 Answers
Player Respawn with Joystick 2 Answers
Kill Player Method Doesn't Work ? 0 Answers
Upgrades not applying after first death 2 Answers