Page 91 - MODUL_PEMROGRAMAN 2D & 3D_Neat
P. 91
22. Tahap selanjutnya buat script baru untuk perpindahan pipa secara acak dan
berjalan.
using UnityEngine;
using System.Collections;
public class pipemove : MonoBehaviour {
public Vector2 pinda = new Vector2 (-1,0);
public float acak = 1;
// Use this for initialization
void Start () {
GetComponent<Rigidbody2D> ().velocity = pinda;
transform.position = new Vector3 (transform.position.x,
transform.transform.position.y – acak * Random. .value, transform.position.z);
}
// Update is called once per frame
void Update () {
}
}
23. Setelah itu masukan script di atas ke pipe dan masukkan pipe ke dalam
forder prefab dengan cara drag and drop.
24. Tahap selanjutnya kita akan membuat pipe keluar terus menerus, dengan
cara buat game object baru beri nama panggilpipe.
Gambar 4.17 Membuat game object baru.
77