前提・実現したいこと
Instantiateによって生成したprefabのオブジェクトRight1
をempty objectであるTest
のオブジェクトにアタッチされているTest
のスクリプトを使って移動させたい。
発生している問題・エラーメッセージ
Right1
が動かない
該当のソースコード
C#
1using UnityEngine; 2 3public class Test : MonoBehaviour 4{ 5 bool a; 6 float e; 7 float f; 8 float g; 9 float time = 30.0f; 10 public GameObject Right1; 11 void Start() 12 { 13 a = true; 14 15 g = 29.0f; 16 17 e = Random.Range(-1.0f, 1.0f); 18 f = 2*e; 19 } 20 21 void Update() 22 { 23 24 time -= Time.deltaTime; 25 26 if (time <= g - 1) 27 { 28 if (a == true) 29 { 30 Instantiate(original: Right1, position: new Vector3(e, f, 0.0f), rotation: Quaternion.identity); 31 a = false; 32 33 } 34 Transform herTransform = Right1.transform; 35 Vector3 pos = herTransform.position; 36 pos.x += 1.01f; 37 pos.y += 0.01f; 38 herTransform.position = pos; 39 40 } 41 } 42} 43
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/01 09:18