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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM