Game over not triggering
I am working on a platformer game where you jump around on a pogo stick, and if anything but the stick hits the ground, it's game over. I have set up colliders on my character, and tagged the character in the hierarchy as Character. I'm putting the GameOver detection code on my Environment in the hierarchy, as it includes my ground and obstacles.
Right now I am just trying to get the Debug.Log to print Game Over so that I can know my trigger is working before I get into the fancy stuff, but no matter how hard I make my character bang his head on the ground, it doesnt trigger.
Please help!
Code (it doesnt want to show my first few lines in the codebox here... weird)
.
.
.
public class GameOver : MonoBehaviour
{public Rigidbody RB;
private GameObject character;
bool gameOver = false;
void Start()
{
RB = GetComponent<Rigidbody>();
character = GameObject.Find("/Player/Character");
}
void Update()
{
}
private void OnTriggerEnter(Collider target)
{
if (target.gameObject.tag.Equals("Character") ==true)
{
gameOver = true;
Debug.Log("Game Over");
}
}
}
For the code to show in the box, just click the '101010' icon in the top of the question editor, and paste your entire code. $$anonymous$$ake sure to add some carriage returns so that the rest of your question doesn't get in the code box.
Answer by kbop2000 · Apr 21, 2020 at 02:59 AM
if you want to find object by tag,
GameObject.FindGameObjectWithTag("Character");
and recommended way to compare tags ..
private void OnTriggerEnter(Collider target)
{
if (gameOver) return;
if (target.CompareTag("Character"))
{
gameOver = true;
Debug.Log("Game Over");
}
// this
//if (target.gameObject.tag.Equals("Character") == true)
//{
// gameOver = true;
// Debug.Log("Game Over");
//}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612232003im_/https://answers.unity.com/themes/thub/images/avi.jpg)