【发布时间】:2019-01-13 16:29:28
【问题描述】:
我的问题是:我有一个包含武器对象的玩家,我的武器对象包含以下脚本:
private void FixedUpdate()
{
AutomaticFirearmShoot();
}
public void AutomaticFirearmShoot()
{
if (Input.GetButton("Fire1") && Time.time > _nextFire)
{
_nextFire = Time.time + _fireRate;
_player.GetComponent<NetworkShootManager>().CmdShoot();
}
}
我的根播放器也包含这个脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class NetworkShootManager : NetworkBehaviour
{
private void Update()
{
if (!isLocalPlayer)
{
return;
}
}
[Command]
public void CmdShoot()
{
Debug.Log("shooting");
}
}
所以当我构建游戏时,只有宿主玩家可以调用CmdShoot方法。
另外,我的播放器有网络身份组件。
【问题讨论】:
标签: c# unity3d networking