Unity3D中用代碼實(shí)現(xiàn)物體的左右循環(huán)移動(dòng)的方式如下: 1、新建一個(gè)Cube,在Cube X軸的正方向放置一個(gè)空物體或者其他GameObject,Cube和空物體的Y值一致,確保2者在同一水平線上; 2、把下列代碼保存為C#,賦給Cube,并在Inspector視圖中,把空物體賦到腳本的PointB中; using UnityEngine; using System.Collections; public class Moving : MonoBehaviour { public Transform PointB; private int _direction = 1; private float _pointA; // Use this for initialization IEnumerator Start () { _pointA = transform.position.x; while (true) { if (transform.position.x < _pointA) { _direction = 1; } if (transform.position.x > PointB.position.x) { _direction = -1; } transform.Translate(_direction * 2 * Time.deltaTime,0,0); yield return 0; } } }
網(wǎng)站導(dǎo)航
- zblogPHP模板zbpkf
- zblog免費(fèi)模板zblogfree
- zblog模板學(xué)習(xí)zblogxuexi
- zblogPHP仿站zbpfang