Problem with OnControllerColliderHit

Soo im making some deadlyobjects for my game and my code lokes like this

private var dead = false;
var CallHPScript = Health;

function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.gameObject.tag == “spike”);
{
dead = true;
}
}

function LateUpdate();
{
if(skinihp == true)
{
Health.curHp -= 100.0;
}
}

@script RequireComponent (Health)

Nothing happens :confused:
Soo i want to make that the object called spike takes 100 HP every time he touchs it … my max hp is 300 …

Have you tried using OnCollisionStart or OnTriggerEnter depending on what you want to achieve?

No , can you explain more about that two functions

Sure,

If two objects collide and one of them has trigger set to true the object will just pass trough each other but the collision will be detected and OnTriggerEnter OnTriggerExit OnTriggerStay will be called when appropriate event is triggered. This is useful for switches, invisible triggers that you will use for triggering events in game, enemies that don’t need to collide, what ever you can think of.

more info: Unity - Scripting API: Collider

OnCollisionStart is same thing as OnTriggerEnter it’s just called when two objects collide and neither one has trigger set to true, so they will physically collide and appropriate functions will be called as events are triggered.

Depending on your needs any of these two functions can be used to accomplish your goal.

im using usually c# instead of java but in java it would work something like this

function OnCollisionEnter(someCollision : Collision)
{
     if(someCollision.gameObject.tag == "spike")
    {
        //CODE TO HANDLE COLLISION WITH OBJECTS TAGGED SPIKE
    }
}

Nisam te bas skonto Dejane ajde na onu vasu FB stranicu poslo sam vam PM :slight_smile:

Done!