###前提・実現したいこと
ランダムに選ばれたオブジェクト(Prefabになっている)を右から左に移動させたい。
スクリプトは空のオブジェクトにアタッチしているのでこの状態では空のオブジェクトが移動してしまいます。
ランダムに選ばれたオブジェクトを移動させる方法があれば、ご教授願います。
###該当のソースコード
c#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class RandomStageController : MonoBehaviour { 6 private Rigidbody2D rb2D; 7 public GameObject[] Train; 8 float vector = 1; //移動速度 9 10 void Start(){ 11 StartCoroutine (SpeedUp()); 12 StartCoroutine (Walls()); 13 rb2D = GetComponent<Rigidbody2D>(); 14 } 15 16 void Update(){ 17 this.transform.position += new Vector3(vector, 0, 0); //移動 18 } 19 20 IEnumerator SpeedUp(){ 21 while (vector <= 30) { 22 vector++; 23 yield return new WaitForSeconds (10f); //10秒に一度vectorの速度をアップ 24 25 } 26 } 27 28 IEnumerator Walls(){ 29 while (true) { 30 int number = Random.Range (0, Train.Length); 31 Instantiate(Train[number],transform.position,transform.rotation); //ランダムに抽選 32 yield return new WaitForSeconds (3f); //3秒に一度 33 } 34 } 35}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/07/20 03:37
2018/07/20 04:06
退会済みユーザー
2018/07/20 04:37
2018/07/20 04:58