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