我正在两个navmesh代理之间绘制一个线渲染器,并为其分配一个方向箭头纹理。但问题是它垂直地站在我的道路结构的顶部。我需要平躺下来。
在两个代理之间绘制线的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class ParkingLevel : MonoBehaviour
{
[Space(10)]
[Header("For Path Rendering")]
public Transform targetAgent;
public NavMeshAgent agent_ParkingPoint;
public LineRenderer line;
public static ParkingLevel Instance;
void OnEnable()
{
if (Instance == null)
{
Instance = this;
line.startWidth = 3;
line.endWidth = 3;
return;
}
}
void OnDisable()
{
Instance = null;
}
void LateUpdate()
{
GetPath();
}
public void GetPath()
{
targetAgent = PlayerActivitiesManager.Instance.busAgent.transform;
line.SetPosition(0, agent_ParkingPoint.gameObject.transform.position);
agent_ParkingPoint.SetDestination(targetAgent.position);
DrawPath(agent_ParkingPoint.path);
agent_ParkingPoint.isStopped = true;
}
private void DrawPath(NavMeshPath path)
{
if (path.corners.Length < 2)
return;
line.positionCount = path.corners.Length;
for (var i = 1; i < path.corners.Length; i++)
{
line.SetPosition(i, path.corners[i]);
}
}
}
以下是我对线条渲染器的设置:
1条答案
按热度按时间ymdaylpp1#
你可以使用一个小技巧:
LineRenderer
设置为position = Vector3.zero
Use World Space = false
-〉将使用局部空间位置x = 90°
Z
和Y
轴比如