Question by
newmaker · May 25, 2016 at 03:38 AM ·
c#enemyconnectionpunsynchronize
How do I synchronize attacks and damage to enemys?
I got a PUN Network server for my game, my position and rotation got Instantiated from the Script but not the Attacks and Damage to the Enemys. How do I instantiate these ?
Here is my PhotonNetwork & PhotonPlayer script:
public class NetworkManager : MonoBehaviour {
const string VERSION = "v0.0.1";
public string roomName = "slasherRoom";
public string playerPrefabName = "Character";
public Transform spawnPoint;
void Start ()
{
PhotonNetwork.ConnectUsingSettings (VERSION);
}
void OnJoinedLobby()
{
RoomOptions roomOptions = new RoomOptions () { isVisible = false, maxPlayers = 4};
PhotonNetwork.JoinOrCreateRoom (roomName, roomOptions, TypedLobby.Default);
}
void OnJoinedRoom()
{
PhotonNetwork.Instantiate (playerPrefabName, spawnPoint.position, spawnPoint.rotation, 0);
}
}
public class NetworkPlayer : Photon.MonoBehaviour {
public GameObject myCamera;
bool isAlive = true;
Vector3 position;
Quaternion rotation;
float lerpSmoothing = 10f;
Animator myAnim;
void Start ()
{
if (photonView.isMine)
{
GetComponent<CharacterController>().enabled = true;
gameObject.name = "Me";
myCamera.SetActive (true);
GetComponent<Player> ().enabled = true;
GetComponent<Rigidbody>().useGravity = true;
GetComponent<SlashAttack>().enabled = true;
GetComponent<HealthBar>().enabled = true;
//myAnim.GetComponent<Animator>().enabled = true;
}
else
{
gameObject.name = "Network Player";
StartCoroutine("Alive");
}
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.SendNext(transform.position);
stream.SendNext(transform.rotation);
}
else
{
position = (Vector3)stream.ReceiveNext();
rotation = (Quaternion)stream.ReceiveNext();
}
}
IEnumerator Alive()
{
while(isAlive)
{
transform.position = Vector3.Lerp(transform.position, position, Time.deltaTime * lerpSmoothing);
transform.rotation = Quaternion.Lerp(transform.rotation, rotation, Time.deltaTime * lerpSmoothing);
yield return null;
}
}
Here is my Character view in the Hirarchy and Inspector.
punproblem.jpg
(223.8 kB)
Comment