Jump to content

Help me C# basic script wont work dont know why

trent69

I am programming in C# and am developing a game over on Unity and am facing a problem with my code.

the link to video where he sets up the die lines...  

 

I have been watching this series and facing problems like very one and fixing them but this one I just cant figure out whats going wrong. I have set up the Die shortcut as shown in the scrpt beow and it works fine on the hitting the enemy but when I put it on to the falling it just dosen't work, even if i put the whole script instead of the Die it doesn't work. Pls help Btw this is a player movement script which is added to a block allowing it to move, and when it falls off the world it doesnt die instead just falling forever.

 The code doesn't like to copy over here so i will add a photo:

Capture.PNG.d2c6f4e8aa0b8a323ac96d1a66d2

Link to comment
Share on other sites

Link to post
Share on other sites

On 3/22/2016 at 9:10 AM, trent69 said:

-nom-

You've put the 

if(transform.position.y < -2.0f)
{
    Die();
}

inside OncollisionEnter function. This only gets called when you collide with something (like an enemy)

You want to put that if statement in Update() instead (after the translate to avoid 1-frame lag) so that it get's checked every frame.

Your code would only work now if you collided with something while already falling through a world.

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×