错误:
Failed to call function WeaponFire of class gunScript
Calling function WeaponFire with no parameters but the function requires 1.
UnityEngine.Component:SendMessage(String)
weaponController:Update() (at Assets/Fps scripts/weaponController.cs:12)
这是脚本:
using UnityEngine;
using System.Collections;
//This script instantiates a bullet.
public class gunScript : MonoBehaviour {
public Transform bullet;
//Called by playerStatus script
//Instantiates a bullet which is passed in the arguments from PlayerStatus
void WeaponFire(Transform bullet)
{
Instantiate(bullet, transform.position, transform.rotation);
}
}
我不能让枪射出子弹。
答案 0 :(得分:1)
您还应该包含调用代码。根据错误消息,您在没有参数的情况下调用WeaponFire方法。
好:WeaponFire(子弹)
坏:WeaponFire()
答案 1 :(得分:-1)
从函数中删除子弹转换,它已经公开 你的子弹正在从现有对象中实例化, 你的脚本应该在实例化时获取玩家武器的位置和旋转
确保通过检查员设置子弹。
using UnityEngine;
using System.Collections;
//This script instantiates a bullet.
public class gunScript : MonoBehaviour {
public Transform bullet;
//Called by playerStatus script
//Instantiates a bullet which is passed in the arguments from PlayerStatus
void WeaponFire()
{
Instantiate(bullet, transform.position, transform.rotation);
}
}