您不能调用来调用与参数。这应该工作,如果你从您的拍摄功能删除参数。
Invoke("Shoot", 3f);
然后你的拍摄功能应该是这样的
void Shoot(){
}
,而不是
void Shoot(string...parameter){
}
您的评论后,有另一种方式来做到这一点。这需要“协同程序”。
IEnumerator Shoot(Collider currentTarget, float delayTime)
{
yield return new WaitForSeconds(delayTime);
//You can then put your code below
//......your code
}
你不能直接调用它。例如,你不能这样做: Shoot(currentTarget, 1f)
;
如果你不喜欢使用StartCoroutine您必须使用**StartCoroutine**(Shoot(currentTarget, 1f));
void Start()
{
//Call your function
StartCoroutine(Shoot(currentTarget, 1f));
}
而且,那么你可以调用内的另一个功能正常的协程功能。我想你可能会喜欢这种方法使整个代码看起来应该像下面的东西:
//Changed the name to **ShootIEnum**
IEnumerator ShootIEnum(Collider currentTarget, float delayTime=0f)
{
yield return new WaitForSeconds(delayTime);
//You can then put your code below
//......your code
}
//You call this function
void Shoot(Collider currentTarget, float delayTime=0f)
{
StartCoroutine(ShootIEnum(currentTarget, 1f));
}
void Update()
{
if (currentTarget != null)
{
Shoot(currentTarget, 0.3f);
}
}
现在,任何时候你想打电话拍摄,你可以现在没有问题致电Shoot(currentTarget, 1f);
。
什么语言? C#或Javascript?拍摄功能在哪里?在另一班还是同班? – Programmer
C#,在同一个班级 – David
已更新我的回答 – Programmer