迷雾系统-人物驱散迷雾

使用linerRender,将人物移动数据动态添加进去,同样是特殊层级让FogCamera渲染

EndCapVertices的数量越多,矩形就变为一个椭圆形的形状,更适合圆形视野探索

当拐点的两个点距离太近,LineRender会发生扭曲,解决方案是在拐点处额外新添几个点作为过渡

下面是我每次鼠标点击移动,就往LineRender里面多新填一行数据,预防拐点变形,我每次点击就新填几行无意义数据进去,超过50个,我就新生成LinerRender

csharp 复制代码
 if (Input.GetMouseButtonUp(0))
      {
         Move(Input.mousePosition);
      }
      
      if (_isCanMove)
      {
         transform.Translate(_dir.normalized*Time.deltaTime*_moveSpeed,Space.World);
         _addLineTimer += Time.deltaTime;
         if (_addLineTimer > 0.1f)
         {
            _addLineTimer = 0f;
            AddLineRender(transform.position);
         }
         
         if (Vector3.Distance(transform.position, _targetPos) < 0.5f)
         {
            transform.position = _targetPos;
            _isCanMove = false;
            AddLineRender(transform.position);
         }
      }

//上面是Update里面的操作
 private void AddLineRender(Vector3 pos)
   {
      _currentLineRenderer.positionCount = _linerIndex+1;
      _currentLineRenderer.SetPosition(_linerIndex,pos);
   }

//鼠标点击生成此方法
   public void Move(Vector2 targetPos)
   {
      if (_currentLineRenderer == null)
      {
         GameObject go = Instantiate(meshPrefab,meshPar.transform);
         go.transform.position = new Vector3(0f, 0f, 1f);
         _currentLineRenderer = go.GetComponent<LineRenderer>();
         _addLineTimer = 0.1f;
         _linerIndex = 0; 
         AddLineRender(transform.position);
      }

      if (_linerIndex > 50)
      {
         GameObject go = Instantiate(meshPrefab,meshPar.transform);
         go.transform.position = new Vector3(0f, 0f, 1f);
         _currentLineRenderer = go.GetComponent<LineRenderer>();
         _addLineTimer = 0.1f;
         _linerIndex = 0;
         AddLineRender(transform.position);
         _linerIndex += 1;
      }
      else
      {
         for (int i = 0; i < 3; i++)
         {
            AddLineRender(transform.position + new Vector3(0.01f*i, 0f, 0f));
            _linerIndex += 1;
         }
      }

//获取移动向量,物体往此方向移动
 Vector3 pos = cam.ScreenToWorldPoint(new Vector3(targetPos.x,targetPos.y,-10f));
      _targetPos = new Vector3(pos.x,pos.y,-9.5f);
      _dir = _targetPos - transform.position;
      _isCanMove = true;
相关推荐
c#上位机5 小时前
halcon刚性变换(平移+旋转)——vector_to_rigid
图像处理·人工智能·计算机视觉·c#·halcon
Miss_SQ5 小时前
Webgl打包后删除StreamingAssets文件夹下多余资源
unity·c#·webgl
小猪快跑爱摄影5 小时前
【AutoCad 2025】【C#】零基础教程(二)——遍历 Entity 插件 =》 AutoCAD 核心对象层级结构
开发语言·c#·autocad
烛阴7 小时前
C# Dictionary 入门:用键值对告别低效遍历
前端·c#
Monkey_Xuan9 小时前
C#中的引用传递和值传递
unity·c#
CreasyChan9 小时前
C# LINQ 深度解析:优缺点与性能陷阱
unity·c#·游戏开发
精神小伙就是猛10 小时前
C# sealed密封 追本溯源
开发语言·c#
雨季66611 小时前
C 语言学习指南:从入门到实战的系统路径
c#
缺点内向15 小时前
如何在 C# 中创建、读取和更新 Excel 文档
c#·.net·excel
c#上位机15 小时前
halcon创建对象数组——concat_obj
图像处理·计算机视觉·c#·halcon