2016-11-10 82 views
0
using UnityEngine; 
using System.Collections; 

public class Lift : MonoBehaviour { 

    private bool pressedButton = false; 
    private bool isElevatorUp = false; 

    public GameObject target; 

    void OnMouseOver() 
    { 
     pressedButton = true; 
    } 

    void OnMouseExit() 
    { 
     pressedButton = false; 
    } 

    void OnMouseDown() 
    { 
     if(isElevatorUp == false) 
     { 
      target = GameObject.Find("Elevator"); 

     } 
    } 

    void OnGUI() 
    { 
     if(pressedButton == true) 
     { 
      GUI.Box(new Rect(300, 300, 200, 20), "Press to use lift!"); 
     } 
    } 
} 

当我键入target.animation。 然后在最后一点后,我看到一些属性,但不玩。为什么GameObject.animation没有play属性?

它应该是:target.animation.Play但Play不存在。

+1

实际上GameObject.animation属性已被弃用 – luizcarlosfx

回答

2

现在不推荐使用GameObject上的直接动画播放函数调用,例如GameObject.PlayAnimation(...)。 您必须使用GetComponent才能获取动画组件,然后再调用Play()函数。

target.GetComponent<Animation>().Play(); 

还有动画师。如果您使用Animator代替动画:

target.GetComponent<Animator>().Play("animationState"); 
相关问题