c# - 如何在一定时间内延长对角线渲染器线

标签 c# unity3d

我通过将以下脚本附加到一个空的游戏对象来创建对角线渲染器。如何将线两端的长度延长一半,以及如何沿 x 轴将线延长 1 个单位?两者都在一定时期内。

public class DiagonalLine : MonoBehaviour {

bool firstLineComplete = false;
LineRenderer diagLine;

public Vector3 startPoint = new Vector3 (0, 0, 0);
public Vector3 endPoint = new Vector3 (1.0f, 1.0f, 0);

public float lineDrawSpeed;
// Use this for initialization
void Start () {

    diagLine = gameObject.AddComponent<LineRenderer>();
    diagLine.material = new Material (Shader.Find ("Sprites/Default"));
    diagLine.startColor = diagLine.endColor = Color.green;
    diagLine.startWidth = diagLine.endWidth = 0.15f;

    diagLine.SetPosition (0, startPoint);
    diagLine.SetPosition (1, endPoint);

    }
}

enter image description here

最佳答案

这是基本的矢量数学。

你有一行(从头到尾):

 Vector3 v = start - end;

如果出现以下情况,则每边延伸一半:

 extensionA = start + (v * 0.5f);
 extensionB = end + (v * -0.5f);

如果需要扩展 1,则归一化:

 Vector3 v = (start - end).normalized;
 extensionA = start + v;
 extensionB = end + (v * -1f);

关于c# - 如何在一定时间内延长对角线渲染器线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47145383/

相关文章:

c# - 删除或更改 unity 5 默认启动画面 "Made with unity"

c# - 将历史数据保存在数据库中

c# - 使用 WCF 从 .svc 创建 .cs 文件的正确方法

c# - .NET 项目中的 ToolsVersion 规范

c# - Unity3d显示状态栏

c# - Unity3D协程编译错误

java - 在 Unity 3d(3D) 中翻转重力

c# - 如何在单声道的 C# 中编写简单的基于 REST 的服务器?

C#2.0逐行读取并复制Xml文件?

c# - 最小化时运行游戏(Unity)