Hey,
My Unity Answers Question got rejected . I really need help so I came here. Here is the original question;
How to die when a sprite hits you?
0
Help!
I’m making a 3D game where a sprite chases you (Like Slender) When the sprite hits you, It sends you to the game over screen. But it doesn’t. It just goes through you. Can anyone help? I’ve tried all other things I could find, but none worked. If you need more info, just ask.
Code
#pragma strict
functionOnCollisionEnter(other :Collision){
Application.LoadLevel(“gameover”);
}
I found this code online. It doesn’t make any errors in the console.
Hey,
I’ve tried all of the suggestions and they haven’t worked.
They both have a rigidbody component. What needs to be ticked /selected in the rigidbody component.
( I’m a Unity noob…)
Ok, first off. When posting code, do as I asked. Post it in code tags, it makes it easier to read.
function someDopeAssFunction(){
doSomething();
}
Second, it could be many things.
A. Your objects don’t have colliders or rigidbodies. You say they do tho. Check.
B. your objects don’t have the script attached. Check.
C. No level called game over exists.
Finding the reason for an error, of whatever sort, takes detective work.
Good luck Sherlock!
Actually, with the triggers issue, here’s how I have approached a problem like this:
First, is scene actually in the build settings? if not, then it will definitely fail.
Are the tags set right? I often got problems in projects where a new prefab, such as a new car, wouldn’t register the right things, of which was caused by my forgetfulness, i.e. forgot to tag the car, “car”
The way collisions work: collider->collider, trigger->collider, trigger->trigger
But trigger->collider registers nothing…
…so, try attaching the script to the player instead, make sure the enemies aren’t triggers (same with the player) and make sure the player script checks the tags o see if the collider is tagged “enemy.” also, check that all objects are tagged appropriately.