网上祭奠类网站怎么做河北自助建站系统平台
我们打开上一篇03的射线双击项目,

本章要做的事情是在PlayerRayNavgation脚本中添加一个移动光标,实现人物在场景中鼠标点击移动后在移动过程中出现移动目标光标的效果。
在unity编辑器中创建一个Plane

重命名为MovementSign

删掉碰撞器

创建一个材质

选择 旧版着色器 Legacy Shaders

继续选择 粒子 Particles

最后选择 顶点照明混合 VertexLit Blended

修改为红色,并且添加一个图标

拖拽至移动光标MovementSign

修改大小

修改移动光标MovementSign 的 y值改为-1
接下来增加PlayerRayClickNavigation脚本的代码如下


using UnityEngine;
 using UnityEngine.AI;
 public class PlayerRayClickNavigation : MonoBehaviour{
     NavMeshAgent meshAgent;
     Vector3 targetPos;
     #region 02主角动画
     PlayerAnimator playerAnimator;
     #endregion
     #region 03鼠标双击
     //计时
     float followMouseTimer;
     //计数鼠标点击次数
     int clickCount;
     //控制主角是否跟随鼠标
     bool followMouse;
     #endregion
     #region 04移动光标
     Renderer movementSign;
     bool hasArrived = false;
     #endregion
     void Awake(){
         meshAgent = GetComponent<NavMeshAgent>();
         #region 02主角动画
         playerAnimator = GetComponentInChildren<PlayerAnimator>();
         #endregion
         #region 04移动光标
         if(movementSign == null)
             movementSign = GameObject.Find("MovementSign").GetComponent<Renderer>();
         #endregion
     }
     void Start(){
         Invoke("EnableNavMesh", 0.2f);
     }
     void EnableNavMesh(){
         targetPos = transform.position;
         meshAgent.enabled = true;
     }
     void Update(){
         if (!meshAgent.enabled)
             return;
         #region 02人物动画
         playerAnimator.PlayLocomotionAnimation(transform.position, targetPos);
         #endregion
         if (Input.GetMouseButtonDown(0)){
             #region 03鼠标双击
             clickCount++;
             followMouse = false;
             #endregion
             ClickMouse();
         }
         #region 03鼠标双击
         DoubleClickMouse();
         #endregion
         #region 04移动光标
         if (!hasArrived && Vector3.Distance(transform.position, targetPos) < 0.1f) {
             hasArrived = true;
             movementSign.enabled = false;
         }
         #endregion
     }
     void ClickMouse(){
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit, Mathf.Infinity,LayerMask.GetMask("Land"))){
             targetPos = hit.point;
             meshAgent.SetDestination(targetPos);
             #region 04移动光标
             movementSign.transform.position = hit.point + new Vector3(0, 0.01f, 0);
             movementSign.enabled = true;
             hasArrived = false; 
             #endregion
         }
     }
     #region 03鼠标双击
     void DoubleClickMouse(){
         //开启开关 主角跟随鼠标移动
         if (followMouse)
             ClickMouse();
         else{
             //判断自上次鼠标点击以来是否经过了足够长的时间来区分单击与双击事件
             if (Time.time - followMouseTimer >= 0.5f){
                 //已超出规定时间 重新计时
                 followMouseTimer = Time.time;
                 //重置点击计数器为零
                 clickCount = 0;
             }
             else{
                 //在时间间隔内
                 if (clickCount > 1)
                     //双击
                     followMouse = true;
             }
         }
     }
     #endregion
 }
 运行即可实现移动目标中的光标效果

到达位置后光标会消失

本篇只实现了移动中的目标光标效果,接下来还需做以下内容:
1.让主角打开背包或者其他UI时点击UI功能时不会使人物进行移动(禁止射线穿透行为)
2.新输入系统的人物转向功能
3.摄像机跟随主角移动
4.人物释放技能
5.怪物的生成
6.怪物UI信息(笼)
7.3D模型投射UI(UGUI)界面
以及开放回合制、坐骑系统、宠物系统、背包系统、神炼系统、商城系统、Boss的目标跟随任务导航系统以及UI播放3D动画效果等等。
具体项目运行效果请关注water1024的b站视频项目演示《破碎纪元》

【Unity回合2.5D】破碎纪元_单机游戏热门视频 (bilibili.com)
https://www.bilibili.com/video/BV1rZY4e9Ebs/?spm_id_from=333.999.0.0
