[Unity3D] Character Movement and Animation Switching (Animator)

· 886 views · updated May 30, 2018

Translated by AI from 中文 · View original

This post was recovered from Internet Archive snapshots; some images may be lost.

State Machine (Animator)

Controls character animation playback, arrow keys control animation switching

Code-Controlled Character Movement

public NavMeshAgent agent;
public Animator anima;
  
void Update () {
        if (Input.GetMouseButtonDown(0)){   // 按下鼠标左键,1是右键
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);// 获取屏幕坐标,转换射线
            RaycastHit hit; //保存射线碰撞信息
            if (Input.GetMouseButtonDown(0)){   // 按下鼠标左键,1是右键
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);// 获取屏幕坐标,转换射线
            RaycastHit hit; //保存射线碰撞信息
            if(Physics.Raycast(ray, out hit))// 判断碰撞
            {
                // Console.WriteLine(hit.point);
                agent.SetDestination(hit.point);// 传达指令,控制运动
            }
        anima.SetFloat("speed", agent.velocity.magnitude);// 设置Animator中speed的值
        }

Parameter Angular Speed Controls Turning Speed

Comments