【发布时间】:2019-10-11 17:58:01
【问题描述】:
我正在开发一个简单的虚拟游览应用程序,我将相机放置在球体中,用 360 度全景照片映射球体,然后单击箭头对象(精灵)以向前和向后导航。下面的脚本实例化了数组中的下一个球体(与下一张 360 度照片映射),同时销毁当前球体,模拟应用程序中的向前运动。它似乎工作正常。
public void Update()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
if (hit.collider != null)
{
Destroy(currentObject);
currentIndex++;
currentIndex = currentIndex >= Spheres.Length ? 0 : currentIndex;
currentObject = Instantiate(Spheres[currentIndex]);
}
}
}
}
我的问题是如何反转数组的顺序,以便我可以单击“后退”箭头来实例化数组中的前一个预制件。
我认为这就像currentIndex--; 一样简单,但我无法让它工作。非常感谢任何帮助。
【问题讨论】:
标签: arrays unity3d reverse instantiation destroy