15、子弹开火的逻辑
在Player.cs中添加
public class Player : NetworkBehaviour
{
……
private float nextFire; //下一次开火的时间
public float fireRate = 0.75f; //两次开火至少相隔的时间
public Transform shotPos; // 开火位置
……
private void FixedUpdate()
{
……
//开火
if (Input.GetButton("Fire1"))
{
if (Time.time > nextFire)
{
nextFire = Time.time + fireRate;
CmdShoot((short) (shotPos.position.x * 10), (short) (shotPos.position.z * 10));
}
}
}
……
[Command]
void CmdShoot(short xPos, short zPos)
{
Vector3 shotCenter =
Vector3.Lerp(shotPos.po