Hello I’m having a floating button and i want it to be klicked when a specific game object hits it, when it drops on the button for example. How do I do this?
Does it HAVE to be a UI button? Just make a sprite gameobject and add script that make it behave like a button. Then make use of the same old collisions techniques you would with any other gameobjects.
This will mimic most of the behaviors of a button:
void OnMouseEnter() {
if(enabled)
gameObject.GetComponent<SpriteRenderer>().sprite = hoverSprite;
}
void OnMouseExit() {
if(enabled)
gameObject.GetComponent<SpriteRenderer>().sprite = defaultSprite;
}
void OnDisable() {
gameObject.GetComponent<SpriteRenderer>().sprite = disabledSprite;
}
void OnEnable() {
gameObject.GetComponent<SpriteRenderer>().sprite = defaultSprite;
}
void OnClick() {
OnClick2();
}
void OnMouseDown() {
OnClick2();
}