Instantiateで生成したオブジェクトcloneのSpriteを、ボタンで別のSpriteに変更したいと考えております。
しかし、ボタンのスクリプトにはinspectorでprehabの方しか指定できません。
下記がSpriteを変更する側のObjectについているスクリプトです。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Sprite_chg : MonoBehaviour 6{ 7 [SerializeField] 8 public Sprite card_red; 9 10 [SerializeField] 11 public Sprite card_white; 12 // Start is called before the first frame update 13 public void Switch(bool a) 14 { 15 Debug.Log(a); 16 if(a==true&&this.gameObject)this.gameObject.GetComponent<SpriteRenderer>().sprite = card_white; 17 if (a == false && this.gameObject) this.gameObject.GetComponent<SpriteRenderer>().sprite = card_red; 18 } 19 20 void Start() 21 { 22 this.GetComponent<Sprite_chg>(); 23 this.gameObject.GetComponent<SpriteRenderer>(); 24 } 25 26 // Update is called once per frame 27 void Update() 28 { 29 30 } 31} 32
こちらがボタンのスクリプトです。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Switch_button : MonoBehaviour 6{ 7 [SerializeField] 8 private Sprite_chg chg; 9 private bool switch_signal = false; 10 // Start is called before the first frame update 11 void Start() 12 { 13 manage = manager.GetComponent<Manager_circle>(); 14 } 15 public void Switch_start() 16 { 17 chg.Switch(switch_signal); 18 if (switch_signal == false) 19 { 20 switch_signal = true; 21 } 22 else 23 { 24 switch_signal = false; 25 } 26 } 27 // Update is called once per frame 28 void Update() 29 { 30 31 } 32} 33
Debug.Logではきちんとswitch_signalの値の受け取りが出来ているので、スクリプトエラーはないかと思います。
ボタン側のinspectorではprehab化しているSpriteを変更させるオブジェクトを指定しております。
繰り返しになりますが、prehab化したオブジェクトをInstantiateし、その(clone)とついているオブジェクトのSpriteを変更したいと考えております。
どうかよろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/09/06 07:58
2019/09/06 14:25