例如:你想调用已经实例了的Player对象里的PlayJumpTo 代码里的Jump()函数
private PlayJumpTo playJumpto;
private GameObject playerObj;
void Start()
{
playerObj = GameObject.FindWithTag ("Player");
playJumpto = playerObj.GetComponent<PlayJumpTo>();
}
void Fun()
{
playJumpto.Jump();
}
那么这样就可以了,注意要将Player对象tag自己新建指定为Player,而Jump()函数也要是Public。
时间: 2024-11-05 11:31:13