Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Door Script not working!!

Discussion in 'Scripting' started by Mo3, May 24, 2016.

  1. Mo3

    Mo3

    Joined:
    May 24, 2016
    Posts:
    2
    It gives me the error CS1061
    Here is the code:
    using UnityEngine;
    using System.Collections;

    public class Doors : MonoBehaviour {

    Animation animation;
    bool doorOpen;

    void start()
    {
    doorOpen = false;
    animation = GetComponent<Animation>();
    }

    void OnTriggerEnter(Collider col)
    {
    if(col.gameObject.tag == "Player")
    {
    doorOpen = true;
    DoorControl("Open");
    }
    }
    void OnTriggerExit(Collider col)
    {
    if (doorOpen)
    {
    doorOpen = false;
    DoorControl("Colse");
    }
    }
    void DoorControl(string direction)
    {
    animation.SetTrigger(direction);
    }
    }
     
  2. iSleepzZz

    iSleepzZz

    Joined:
    Dec 23, 2012
    Posts:
    201
    This: "error CS1061" means nothing to me.
    Any other information on the error? That would be helpful.
    But I mean... from the little information I have, I see you can get a null if you do not have a "Animation" component on this gameobject.
    Also, is it supposed to be "Animation" or "Animator"??? I think it should be animator not animation.
     
  3. Mo3

    Mo3

    Joined:
    May 24, 2016
    Posts:
    2
    WAIT, IT WORKED! I CHANGED IT TO ANIMATOR AND IT JUST STARTED WORKING!
     
  4. iSleepzZz

    iSleepzZz

    Joined:
    Dec 23, 2012
    Posts:
    201
    Well good, I'm glad you got it working.
     
  5. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148