```以下是一个大乱斗的客户端源码 仅供参考
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BaseHuman : MonoBehaviour
{
//是否正在移动
protected bool isMoving = false;
//移动目标点
private Vector3 targetPosition;
//移动速度
public float speed = 1.2f;
//动画组件
private Animator animator;
//描述
public string desc = “”;
public int hp;
public bool isAttacking = false;
public float attackTime = float.MinValue;
//移动到某处
public void MoveTo(Vector3 pos)
{
Debug.Log("MoveTo");
targetPosition = pos;
isMoving = true;
animator.SetBool("isMoving", true);
}
//移动Update
public void MoveUpdate()
{
if (isMoving == false)
{
return;
}
Vector3 pos = transform.position;
transform.position = Vector3.MoveTowards(pos, targetPosition, speed*Time.deltaTime);
transform.LookAt(targetPosition);
if (Vector3.Distance(pos, targetPosition) < 0.05f)
{
isMoving = false;
animator.SetBool("isMoving", false);
}
}
public void Attack()
{
isAttacking = true;
attackTime = Time.time;
animator.SetBool("isAttacking", true);
}
public void AttackUpdate()
{
if (!isAttacking) return;
if (Time.time - attackTime < 1.2f) return;
isAttacking = false;
animator.SetBool("isAttacking", false);
}
// Use this for initialization
protected void Start()
{
animator = GetComponent<Animator>();
}
// Update is called once per frame
protected void Update()
{
MoveUpdate();
AttackUpdate();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CtrlHuman : BaseHuman
{文章来源:https://www.toymoban.com/news/detail-434058.html
// Use this for initialization
new void Start()
{
base.Start();
}
// Update is called once per frame
new void Update()
{
base.Update();
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
Physics.Raycast(ray, out hit);
if (hit.collider != null && hit.collider.tag == "Terrain")
{
MoveTo(hit.point);
}
}
if (Input.GetMouseButtonDown(1))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
Physics.Raycast(ray, out hit);
if (hit.collider != null && hit.collider.tag == "Terrain")
{
transform.LookAt(hit.point);
Attack();
}
}
}
}文章来源地址https://www.toymoban.com/news/detail-434058.html
到了这里,关于Unity Animaotr 动画转换设置的代码设置条件的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!