1. 程式人生 > >animator 新動畫

animator 新動畫

pub tint 類型 移動 vertical isa sys down tor

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

public class AnimatorCon : MonoBehaviour {
    Animator ani;
    // Use this for initialization
    void Start () {
        ani = GetComponent<Animator>();
    }
    
    // Update is called once per frame
    void Update () {
        
float h = Input.GetAxis("Horizontal");//控制移動 float v = Input.GetAxis("Vertical"); transform.Translate(h*Time.deltaTime,0,v*Time.deltaTime); if (h<0) { transform.localScale = new Vector3(-1,1,1);//反向移動 } else { transform.localScale
= Vector3.one; } if (h!=0||v!=0) { ani.SetBool("IsRun",true); } else { ani.SetBool("IsRun", false); } if (Input.GetKeyDown(KeyCode.Q)) { ani.SetBool("IsAttack",true); } else { ani.SetBool(
"IsAttack", false); } } }

2.int類型

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//animator動畫狀態機int類型的控制
public class DragonControlor : MonoBehaviour {
    Animator ani;
    // Use this for initialization
    void Start () {
        ani = GetComponent<Animator>();
    }
    public void GetButtonQ()
    {
        ani.SetInteger("com", 1);//對paiameters進行設置
    }
    public void GetButtonW()
    {
        ani.SetInteger("com", -1);//對paiameters進行設置
        ani.SetInteger("con", 1);
    }
    public void GetButtonE()
    {
        ani.SetInteger("con", -1);//對paiameters進行設置
    }
    // Update is called once per frame
    void Update () {
        AnimatorStateInfo start = ani.GetCurrentAnimatorStateInfo(0);//判斷當前動畫狀態
        if (start.IsName("dragon_land_on_ground"))
        {
            ani.SetInteger("com", 0);//讓它返回
        }
        if (start.IsName("dragon_die")) 
        {
            ani.SetInteger("com", 0);
        }
        if (start.IsName("dragon_loop_da_loop"))
        {
            ani.SetInteger("con", 0);
        }
    }
}

AnimatorStateInfo aniSta=  ani.GetCurrentAnimatorStateInfo(0);//獲得當前層的動畫片段狀態信息
        if (h != 0 || v != 0)
        {
            ani.SetBool("IsWalk", true);
            if (Input.GetKey(KeyCode.LeftShift))
            {
                ani.SetBool("IsRun", true);
            }
            else
            {
                ani.SetBool("IsRun", false);
            }
        }
        else
        {
            if (aniSta.IsName("run"))//判斷是否正在播放此動畫
            {
                ani.SetBool("IsRun", false);
            }
            ani.SetBool("IsWalk", false);
        }

animator 新動畫