No errors, but not working. Anything wrong with this script?

Hi,

I attempted converting a Java script into a C# and the console and monodevelop read no errors.

Yet the door isn’t opening.

Before I focus on working out what I’ve done wrong through the inspector, I was wondering whether there is anything wrong with this door opening code:

public class Doorscript : Monodevelop {

Gameobject Door;

public void OnTriggerEnter (Collider other) {

if (other.tag == “Player”)

{
Gameobject.Find(“Door”).animation.Play (“door open”);
}
}
}

onTriggerEnter should be OnTriggerEnter with a capital O, for one.

Ah sorry that was a mistype, it does have a capital O. I might change that…

I refuse to believe that MonoDevelop doesn’t give you any errors, because mine goes red immediately. :slight_smile: Also, have a look on how to use code tags properly.

Your code has several errors:

  • Monodevelop should be MonoBehaviour.
  • Gameobject should be GameObject.
  • onTriggerEnter should be OnTriggerEnter.
  • The Door variable is never assigned.

Here’s an untested revision:

public class Doorscript : MonoBehaviour
{
    GameObject Door;

    void Start ()
    {
        Door = GameObject.Find ( "Door" );
    }

    public void OnTriggerEnter ( Collider other )
    {
        if ( other.tag == "Player" )
        {
            Door.animation.Play( "door open" );
        }
    }
}

B

Bliss, it works.
Thanks so much for your help toreau.