- Home /
The question is answered, right answer was accepted
Respawn script not working.
It is not detecting a collision. In the if (col.gameObject......) I put a print function and it doesnt work either.
[SerializeField] private Transform Player;
[SerializeField] private Transform SpawnPoint;
void OnTriggerEnter(Collider col)
{
if (col.gameObject.CompareTag("Enemy"))
{
Player.transform.position = SpawnPoint.transform.position;
}
}
Do you get any error messages? I.e. NullReferenceException?
Before your if state, add the following line to help see what is going on, and help fix it.
Debug.Log("Colliding with " + col.gameObject.name + " with tag " + col.gameObject.tag);
If you get a result in the console, the trigger is working, and the problem is with the IF statement. This will also tell you the name and tag of the colliding object, to help you see what is happening.
Answer by Delacroz · Dec 13, 2019 at 05:13 PM
First of all , verify if both of gameobjects have a RigidyBody
Also ensure both have a collider and at least one of them is a trigger.
Both have a collider, and with is trigger or without it it still doesnt work.
When you added the Debug.Log or Print, did you put it inside the if statement or outside?
Answer by Legend_Bacon · Dec 13, 2019 at 05:22 PM
Hello there,
You should check if your collisions are detected at all, not just with an enemy. Try adding a Debug.Log("Collided with: " + col.gameObject.name);
line at the top of you collision function.
If you're not getting anything, then your setup is missing something: a RigidBody, a collider set as trigger, etc...
We can probably provide more help if you provide more info about your setup. What components are on the player? On the enemy? Does the enemy actually have the "Enemy" tag?
I hope that helps!
Cheers,
~LegendBacon
Collisions are not detected, because I am not getting any info in console. I have rigidbody on both. I could send my project to you on some platform.
Follow this Question
Related Questions
UV mapping icosphere 1 Answer
Polymorphism for decisions in a dialogue editor 1 Answer
How to make these scripts work together? 0 Answers
How can I re-spawn a script component that has been destroyed? 2 Answers
No Monobehaviour scripts in files 1 Answer