获取游戏对象上的某一个脚本
1.根据脚本名获取脚本对象
GetComponent(脚本名string)
2.根据脚本类型获取脚本对象
GetComponent(typeof(脚本名))
3.根据泛型获取
GetComponent<脚本名>()
4.得到子对象的脚本对象
如果自己有该脚本也能获取到
GetComponentInChildren<脚本名>(bool)
bool为true时 子对象禁用也能获取
bool为false时 子对象禁用不能获取
5.得到父对象的脚本
如果自己有该脚本也能获取到
GetComponentInParent<>()
6.尝试获取脚本
TryGetComponent<脚本名>(out 对象名)