迷雾系统-人物驱散迷雾

使用linerRender,将人物移动数据动态添加进去,同样是特殊层级让FogCamera渲染
迷雾系统-人物驱散迷雾_第1张图片
EndCapVertices的数量越多,矩形就变为一个椭圆形的形状,更适合圆形视野探索
当拐点的两个点距离太近,LineRender会发生扭曲,解决方案是在拐点处额外新添几个点作为过渡

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


 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#)