1.实现思想:通过改变物体的坐标值在update函数中实时更新物体的位置。
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
private GameObject gamObj;
// Use this for initialization
void Start () {
gamObj = GameObject.Find("CubeTest");
}
// Update is called once per frame
void Update () {
float val = Random.RandomRange(-1.0f,1.0f);
gamObj.transform.position = new Vector3(0, 0, 0);
gamObj.transform.position = gamObj.transform.position + new Vector3(val,0,0);
}
}
效果如下:
本文介绍了一个简单的Unity脚本,该脚本使指定的游戏对象在每个帧更新时沿X轴随机移动。通过调整物体的坐标值实现动态位置更新。
4293

被折叠的 条评论
为什么被折叠?



