Unity:一个简单的开门动画

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class OpenDoor : MonoBehaviour
{
    
    public string animName="Door";
    private Animation anim;
    /// <summary>
    /// Start is called on the frame when a script is enabled just before
    /// any of the Update methods is called the first time.
    /// </summary>
    void Start()
    {
        anim=transform.parent.gameObject.GetComponent<Animation>();
    }
    private bool state=false;
    private void OnMouseDown() {
        if(state)
        {
            if(anim.isPlaying==false)
                anim[animName].time=anim[animName].length;
            anim[animName].speed=-1;
        }
        else
        {
            anim[animName].speed=1;
        }
        anim.Play(animName);
        state=!state;
    }
}
原文地址:https://www.cnblogs.com/King-of-Dark/p/13127319.html