- Preface
Record a Unity Button event error. After writing the script, and adding the Button component to the object, when adding the OnClick event to it, I found that the method written in the script could not be found, as shown in the figure:
- Problem Analysis
2.1 Troubleshooting of the script
After inspection, there is no compilation error in the script, and it inherits from MonoBehavior.
2.2 Script mounting problem
After consulting the data, the above problem is caused by directly mounting the script to OnClick. OnClick should mount the GameObject object containing the script to realize it. The operation is as shown in the figure:
1. Mount the script on the parent object
2. Mount the GameObject on OnClick
3. Find the method! The effect is as shown in the figure
After adding the script at Button OnClick, I can't find the method I wrote myself
Guess you like
Origin blog.csdn.net/weixin_47952981/article/details/129676862
Ranking