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之后,通过轴坐标进行编写,如有更好的方法或者不懂,请评论在下方......