我正在Unity开发一款射击游戏,当使用Unity多人游戏平台(Unity服务器)时,我遇到了多人游戏模式的问题。我的子弹正在使用网络身份和网络转换。 有些子弹没有出现在射击它们的一侧,但是在另一侧可见,并且会受到伤害。 这是我的拍摄剧本:
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class shoot : NetworkBehaviour {
public GameObject bulletPref;
public int power;
private Transform spawner;
public int damage;
void Start () {
spawner = this.transform.FindChild("Bspwaner");
}
[Command]
public void CmdGunshoot (){
GameObject bull = Instantiate(bulletPref, spawner.position, Quaternion.identity) as GameObject;
bull.GetComponent<bullet>().dmg = damage;
bull.gameObject.transform.GetComponent<Rigidbody>().AddForce(spawner.right * power);
NetworkServer.Spawn (bull);
Destroy(bull, 2.0f);
}
}
这是我的枪脚:
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class bullet : NetworkBehaviour {
public GameObject ie;
public int dmg;
void OnCollisionEnter(Collision other){
Instantiate(ie, transform.position, Quaternion.identity);
NetworkServer.Destroy (this.gameObject);
if (other.gameObject.tag != "Player")
return;
other.gameObject.SendMessage ("takeDamage", dmg);
}
}
这是我的子弹脚本:
{{1}}
问题是什么?
提前致谢,