我将不胜感激任何类型的小费或线索。谢谢。
一些代码可以与一个列表中的所有值共享我的尝试:
协程,用于将所有位置和旋转记录在一个列表中
IEnumerator Record()
{
for (; ; )
{
Debug.Log("Recording");
/*Limit the maximum of values stored; that limits the seconds we can go back in time*/
if (pointsInTime.Count > Mathf.Round(rewindableObjects.Count*(1f/(Time.fixedDeltaTime/Time.timeScale)) * maxrewindTime))
{
for (int i = 1; i < rewindableObjects.Count; i++)
{
pointsInTime.RemoveLast();
}
}
foreach (GameObject go in rewindableObjects)
{
pointsInTime.AddFirst(new PointInTime(go.name,go.transform.position,go.transform.rotation,go.getcomponent<Rigidbody>().velocity));
}
yield return new WaitForSecondsRealtime(0.02f/Time.timeScale);
}
倒带功能可重置所有位置和旋转角度
/*rewind*/
void rewind()
{
foreach(GameObject go in rewindableObjects)
{
if(pointsInTime.Count > 0)
{
PointInTime pointInTime = pointsInTime.First.Value;
if (pointInTime.goName == go.name) //this is way to slow. Solves the problem with objects swapping positions,but looks like a diashow. Needed: Way to differantiate all values belonging to one object in a seperate list or sth.
{
go.transform.position = pointInTime.position;
go.transform.rotation = pointInTime.rotation;
go.getcomponent<Rigidbody>().velocity = pointInTime.velocity; //not working because velocity is applyied,while the rigidbody is still kinematic!!!
pointsInTime.RemoveFirst();
}
}else Stoprewind();
}
}