u3d 控制角色行走

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.EventSystems;public class PlayerController : MonoBehaviour
{private Vector3 target;//目标位置  public NavMeshAgent agent;public Animation anim;//动画  private string locoState = "Locomotion_Stand";private Vector3 linkStart;//OffMeshLink的开始点  private Vector3 linkEnd;//OffMeshLink的结束点  private Quaternion linkRotate;//OffMeshLink的旋转  private bool begin;//是否开始寻路  public RectTransform maxMap;public MeshRenderer dxMeshRenderer;public Canvas canvas;// Use this for initialization  void Start(){//agent = GetComponent();//自动移动并关闭OffMeshLinks,即在两个隔离障碍物直接生成的OffMeshLink,agent不会自动越过  agent.autoTraverseOffMeshLink = false;//创建动画  AnimationSetup();//起一个协程,处理动画状态机  StartCoroutine(AnimationStateMachine());}void Update(){//鼠标左键点击  if (Input.GetMouseButtonDown(0)){if (EventSystem.current.IsPointerOverGameObject()){//float mapX = Input.mousePosition.x - (Screen.width - maxMap.rect.width);//float mapY = Input.mousePosition.y - (Screen.height - maxMap.rect.height);//float realX = (mapX / maxMap.rect.width) * dxMeshRenderer.bounds.size.x - dxMeshRenderer.bounds.size.x / 2;//float realY = (mapY / maxMap.rect.height) * dxMeshRenderer.bounds.size.y - dxMeshRenderer.bounds.size.y / 2;//Debug.Log(realX + "返回" + realY);//等比例求点击点在实体地图中的位置//Vector2 vector2 = Input.mousePosition;//Vector3 target = new Vector3(-vector2.x * dxMeshRenderer.bounds.size.x / maxMap.rect.width, 0, -vector2.y * dxMeshRenderer.bounds.size.z / maxMap.rect.hei


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部