public class ButtonScript : MonoBehaviour
{
public EnemyScript OtherScript;
void OnClick()
{
OtherScript.Attack = true;
OtherScript.AttackType = 0;
}
}
The problem I’m having is that nothing happens when I click the sprite. If I replace OnClick with Start, it works just fine. Do I need to put in something different, or is something else causing the problem?
What is OnClick? Are you sure you spelled that right??? It’s also not public… is this a UI-connected button or are you relying on some other mechanism such as the OnMouse family of functions callbacks? Check the docs for spelling and to make sure you meet 100% of the requirements to get called.
Well, I’m not getting any errors in the console, so I don’t know what’s wrong. I had put the code inside a 2d square, so no, it’s not a UI thing. If OnClick isn’t a thing (which it probably isn’t lol) then what should I do?
I tried OnMouseDown, but it still did nothing when I clicked on it. I am completely lost at this point and don’t know what to use to detect the mouse click. I guess I’ll re-watch the tutorials for the fifth time. Thanks for the help, though
Are you meeting 100% of the requirements? They are stated clearly in the first two lines of the documentation and have to do with having a collider and the location of the script.