2018-11-12 unity 在球上生成弧线作为两点连接线

2018-11-12  本文已影响0人  流光念岁月

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SphereRadin : MonoBehaviour {
List<Vector3> posList = new List<Vector3>();
public float journeyTime = 3.0f;
// The time at which the animation started.
private float startTime;
private float runningTime, percentage,radin;
private Vector3 startPos;
private Vector3 endPos;
public LineRenderer line;
private Vector3 centerPos;

void Awake()
{
    startTime = Time.time;
}
private void FixedUpdate()
{
    runningTime += Time.deltaTime;
    percentage = runningTime / journeyTime;
    radin = Mathf.Sin(Mathf.PI * percentage) + 1f;
    if (percentage > 1)
    {
        return;
    }
    Vector3 riseRelCenter = startPos - centerPos;
    Vector3 setRelCenter = endPos - centerPos;
    transform.position = Vector3.Slerp(riseRelCenter * radin, setRelCenter * radin, percentage);
    transform.position += centerPos;
    posList.Add(transform.position);
    line.positionCount = posList.Count;
    line.SetPositions(posList.ToArray());
}

}

上一篇 下一篇

猜你喜欢

热点阅读