I’m trying to make a button that has SetActive=false when an object A collides with an object B but i’m can’t figure out how.
public UnityEngine.UI.Button F;
void Start()
{
F = GetComponent<UnityEngine.UI.Button>();
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag(“Wall”))
{
F.gameObject.SetActive(false);
}
}
This is not working
If this is a script for a component on the Button object, try:
// public UnityEngine.UI.Button F;
void Start()
{
// F = GetComponent<UnityEngine.UI.Button>();
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag(“Wall”))
{
// F.gameObject.SetActive(false);
gameObject.SetActive(false);
}
}
can you explain why this works?i think there isn’t much difference between F.gameObject.SetActive(false); and gameObject.SetActive(false); (the difference is that the first one can’t be used but the second one can be used .it is really amazing!)Thank you !