I have a game...

Please help! :expressionless:
when I am going to support soldier and colliding to him, THE GUITEXT text IS NOT CHANGING!!!
I am sure my code is right!
ok thankx for any help :slight_smile:
HEre is script:
var targetGuiText : GUIText;

function Start()
{
   targetGuiText.text = "Objective: find a support soldier";
}

function OnCollisionEnter(collision : Collision)
{

    if (collision.gameObject.name == "supportSoldier")
    {
       targetGuiText.text = "Objective complete!";
    }
}

If anyone didn't notice there is more code. It's just above the code block.

Just a quick question, you are attaching the script to the player right?

yes right.

If your soldier is using a character controller you might have to use OnControllerColliderHit() rather than OnCollisionEnter()

1 Answer

1

Is there a rigidbody on at least one of the game objects?

Is there a collider on both of them?

Is the object you’re colliding with definitely called “supportSoldier”?

Is the collision being detected at all? If so, what with? i.e. what does this do:

function OnCollisionEnter(collision : Collision)
{
    Debug.Log("Collided detected with: " + collision.gameObject.name);

    if (collision.gameObject.name == "supportSoldier")
    {
      targetGuiText.text = "Objective complete!";
    }
}