Quantcast
Channel: Answers for "GameObject.Find() work on inactive objects"
Viewing all articles
Browse latest Browse all 45

Answer by peterthepeter140

$
0
0
I was looking for a way to use "FindGameObjectWithTag(tag)" with an inactive GameObject and didn't find any easy alternatives but i came up with this solution: public GameObject Item; public float armorAmount; void Start() { Item = GameObject.FindGameObjectWithTag("Shield1"); if(Item != null) { Item.SetActive(false); } } void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Player") { playerHealth theArmor = other.gameObject.GetComponent(); theArmor.addArmor(armorAmount); Item.SetActive(true); Destroy(gameObject); } } }

Viewing all articles
Browse latest Browse all 45

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>