2016-11-10 5 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.PlayAnimation(...)のようなゲームオブジェクトでの直接アニメーション再生関数呼び出しは非推奨です。 GetComponentを使用してアニメーションコンポーネントを取得し、その後、Play()関数を呼び出す必要があります。

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

アニメーターもあります。アニメーションの代わりにAnimatorを使用している場合:

target.GetComponent<Animator>().Play("animationState"); 
関連する問題