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;
    }
}

 

posted @ 2020-06-14 22:06  Faker_fan  阅读(1541)  评论(0编辑  收藏  举报