Quantcast
Viewing all articles
Browse latest Browse all 1488

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().enabled = true; gameObject.name = "Me"; myCamera.SetActive (true); GetComponent ().enabled = true; GetComponent().useGravity = true; GetComponent().enabled = true; GetComponent().enabled = true; //myAnim.GetComponent().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.** ![alt text][1] [1]: /storage/temp/70700-punproblem.jpg

Viewing all articles
Browse latest Browse all 1488

Trending Articles