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);
}
}
}
↧