前提・実現したいこと
スクリプトでSetActiveをfalseにしたりtrueにしたりしているのに、
objectが消えたり現れたりしない
該当のソースコード
消したり出したりするobjectに付けているスクリプト
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class RedBlockScr : MonoBehaviour 6{ 7 private GameManager gm; 8 // Start is called before the first frame update 9 void Start() 10 { 11 gm = GetComponent<GameManager>(); 12 } 13 14 // Update is called once per frame 15 void Update() 16 { 17 if(gm.SetBlock == 0) 18 { 19 this.gameObject.SetActive(true); 20 } 21 22 if(gm.SetBlock == 1) 23 { 24 this.gameObject.SetActive(false); 25 } 26 } 27}
SetBlockの数値を変えているスクリプト
using System.Collections; using System.Collections.Generic; using UnityEngine; public class GameManager : MonoBehaviour { public int SetBlock; private float timeleft; // Start is called before the first frame update void Start() { SetBlock = 0; } // Update is called once per frame void Update() { Debug.Log(SetBlock); timeleft -= Time.deltaTime; if(timeleft <= 0.0 && SetBlock == 0) { timeleft = 1.5f; SetBlock = 1; } if(timeleft <= 0.0 && SetBlock == 1) { timeleft = 1.5f; SetBlock = 0; } } }
試したこと
RedBlockScrの
C#
1private GameManager gm;
のところをpublicにしたところ、
インスペクターでGameManagerを付けているobjectをアタッチしても、
なぜかプロジェクトを実行した時にアタッチしたものが外れてしまいます。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。