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,,v*Time.deltaTime);
if (h<)
{
transform.localScale = new Vector3(-,,);//反向移动
}
else
{
transform.localScale = Vector3.one;
}
if (h!=||v!=)
{
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", );//对paiameters进行设置
}
public void GetButtonW()
{
ani.SetInteger("com", -);//对paiameters进行设置
ani.SetInteger("con", );
}
public void GetButtonE()
{
ani.SetInteger("con", -);//对paiameters进行设置
}
// Update is called once per frame
void Update () {
AnimatorStateInfo start = ani.GetCurrentAnimatorStateInfo();//判断当前动画状态
if (start.IsName("dragon_land_on_ground"))
{
ani.SetInteger("com", );//让它返回
}
if (start.IsName("dragon_die"))
{
ani.SetInteger("com", );
}
if (start.IsName("dragon_loop_da_loop"))
{
ani.SetInteger("con", );
}
}
}
AnimatorStateInfo aniSta=  ani.GetCurrentAnimatorStateInfo();//获得当前层的动画片段状态信息
if (h != || v != )
{
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);
}
04-18 02:28