前提・実現したいこと
初心者なので超簡単なミスとかだったらごめんなさい。
UnityでほかのScriptの値を変更したいです。
scriptAでVector3の値をList(配列でも良かったのかも?)設定して、そのVector3をGetComponentでScriptBに代入。
ScriptBであるGameObjectのPrefabのinstanceを作成しそのpositionをscriptAで設定したVector3にしようとしています。
実行してみましたが生成されませんでした。
該当のソースコード
C#
1//ScriptA 2 3using System.Collections; 4using System.Collections.Generic; 5using UnityEngine; 6 7public class ScriptA : MonoBehaviour 8{ 9 // Start is called before the first frame update 10 void Start() 11 { 12 13 List<Vector3> a = new List<Vector3>(); 14 a.Add(new Vector3(1,1,1)); 15 a.Add(new Vector3(2,2,2)); 16 GameObject.Find("ScriptB").GetComponent<ScriptB>().ball_pos=a; 17 18 19 } 20 21 // Update is called once per frame 22 void Update() 23 { 24 25 } 26} 27
C#
1//ScriptB 2 3using System.Collections; 4using System.Collections.Generic; 5using UnityEngine; 6 7 8public class ScriptB : MonoBehaviour 9{ 10 public GameObject point_ball; 11 public List<Vector3> ball_pos ; 12 // Start is called before the first frame update 13 public void Start() 14 { 15 16 for(int i=0;i<1;i++) { 17 GameObject go = Instantiate(point_ball); 18 go.transform.position =ball_pos[i]; 19 } 20 } 21 22 // Update is called once per frame 23 void Update() 24 { 25 26 27 } 28} 29
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。