• animator 新动画


    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);
            }
    莫说我穷的叮当响,大袖揽清风。 莫讥我困时无处眠,天地做床被。 莫笑我渴时无美酒,江湖来做壶。
  • 相关阅读:
    js对象
    实习经历日志02
    前端实习经历日志01
    js变量提升
    WebApls-元素(offset, client, scroll)
    WebApls-Bom
    WebApls-DOM的核心总结
    WebApls-节点01
    javascript-
    Javascript-字符串对象
  • 原文地址:https://www.cnblogs.com/huang--wei/p/9609485.html
Copyright © 2020-2023  润新知