- Home /
What is wrong with my script for Opening a door on click
using UnityEngine; using System.Collections;
public class DoorOpener : MonoBehaviour {
private bool doorOpen = false;
private float animationFinished = 0;
void Update (){
if (Input.GetMouseButtonDown (1))
{
Debug.Log ("Ive been clicked");
if(Time.time > animationFinished)
{
if(doorOpen)
{
animation.Play("Door Close");
}
else
{
animation.Play("Door open");
}
animationFinished = Time.time + 1;
doorOpen = !doorOpen;
}
}
} }
I am getting these errors when I try to use the above script
Assets/DoorOpener.cs(25,15): error CS1061: Type UnityEngine.Component' does not contain a definition for
Play' and no extension method Play' of type
UnityEngine.Component' could be found. Are you missing an assembly reference?
Can someone please explain what is wrong
Answer by Vega4Life · Nov 12, 2018 at 08:26 PM
animation has been deprecated and you need to do GetComponent() instead. Thus, get a reference to your animation in Awake, then give it a go.
Your answer
Follow this Question
Related Questions
door that closes by itself 2 Answers
Is it possible to create a hole for a door in a wall-like cube? 2 Answers
Private and public variables 2 Answers
How to make a double sliding door? 1 Answer
Go through door, by loading next scene, with key-press 1 Answer