mojing SDK根據座標進行移動
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class transforms : MonoBehaviour
{
public Text[] texts;//螢幕顯示
public Transform textss;//焦點座標
public GameObject[] cameras;//移動camera物體
public int VSpeed=3;//移動速度
private float times = 0;//間隔時間
private float newTime_Distance = 0;//當前位移
private float beforeTime_Distance = 0;//上一幀位移
public void newDistance()
{
//camera的Z軸變化距離
beforeTime_Distance = textss.position.z;
}
void Update()
{
newDistance();// 每幀調一下
if (Mathf.Abs(newTime_Distance - beforeTime_Distance) >= 0.001f)//當前幀距離-上一幀距離的絕對值>=時間
{
times = 0;
newTime_Distance = beforeTime_Distance;
texts[0].text = Time.time.ToString();
}
else
{
times += Time.deltaTime;//時間累加
if (times >= 2)
{
texts[3].text = times.ToString();
for (int i = 0; i < cameras.Length; i++)
{
//texts[0].text = (num_i++).ToString();
cameras[i].transform.Translate(Vector3.forward * VSpeed * Time.deltaTime);//向前移動
}
}
}
}
}
注:此方法在mojing sdk for unity之後,通過軸座標進行編寫,如有更好的方法或者不懂,請評論在下方......