- Home /
calling animation on gameobject
i got a bit of a problem here everything works EXCEPT for the animation wont play since i cant make it link the animation to the animation.Play("open1"); anyone know how to? the script looks like this and the script is put on a collider a child of Door
using UnityEngine;
using System.Collections;
public class ActivateDoor : MonoBehaviour {
public Transform door; // select the door in the inspector
private bool colidingThisDoor = false;
void Start () {
// select the parent as the door, as adviced, if it wasn't manually set
if (door == null) {
door = transform.parent;
}
}
void OnTriggerEnter (Collider other) {
colidingThisDoor = true;
}
void OnTriggerExit(Collider other) {
colidingThisDoor = false;
}
void Update () {
if (colidingThisDoor) {
if (Input.GetKeyDown("e")){
// Debug.Log ("E was pressed for door "+ door.name +" on collider "+ transform.name);
animation.Play("open1");
}
}
}
}
thanks alot in advance!
Answer by nasapc123 · Sep 30, 2011 at 11:56 PM
i cant comment on my above post caus of moderation |-( so i would think change animation.play to door.animation.Play("open1");
oh my god... im a retard.... ofcourse its that simple -.- thank you so much man.... (and i was before calling the animation on the collider on wich i had attached the script ^^) thanks alot though... im still very new to the whole coding thing, but i try to learn :) thanks alot!
Answer by nasapc123 · Sep 30, 2011 at 11:56 PM
in not great with c# but it looks like this script isnt on the door object, but you are calling animation.play on the player, not the door?