Godziu
February 23, 2014, 4:12pm
1
Hello
I want to make it like this : when character hits vertical object , its game over . I create obstacles like this :
Instantiate(obj[1], transform.position, Quaternion.identity)
How can i code this in c#? I suppose i can’t do it like this:
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
Application.LoadLevel(1);
return;
}
screen :
http://i.imgur.com/LRn8rNa.png
That should work, if you include it in a script attached to the prefab. But wouldn’t it be easier to check the player collisions for the obstacles, not the obstacles for the player?
As FarmerJoe says, you should just have a script on your player that says:
void OnTriggerEnter2D(Collider2D colObj)
{
if(colObj.tag == "Objects that can kill me")
{
Application.LoadLevel(1);
}
}
This way you only have 1 script for it in the scene, instead of a script on each prefab in the scene.