Unity PVP script
Options
So i've gotten to the point in this project where I have two players connecting to this cloud server. I have gotten collision down to a science, but I am unable to manifest a killing point for the sword that kills the dying player.
Here's the script for the player:
and the script for the sword:
basically what i'm looking for is this result:
Here's the script for the player:
using UnityEngine; using System.Collections; public class playerStats : MonoBehaviour { public hitEnemy weaponScript; public Transform health; private float hpWidth; private PhotonView myPhotonView; public PhotonView pv; private int Kills; public int rctDied; // Use this for initialization void Start () { hpWidth=health.transform.localScale.x; myPhotonView = PhotonView.Get(this); } // Update is called once per frame void Update () { } [RPC] void meleeHit(float damage, string senderID, PhotonMessageInfo p1){ if(hpWidth >0.0f) {hpWidth -= damage; health.transform.localScale = new Vector3 (hpWidth, 0.6000001f, 0.5f); } else { //weaponScript.kills += 1; Debug.Log (p1.photonView.name+" Killed "+senderID); myPhotonView.RPC("addKill", PhotonTargets.AllBuffered, senderID); //Debug.Log (myPhotonView.viewID+" Dead"); } } [RPC] void addKill(string hitName, PhotonMessageInfo info){ if(hpWidth>0.0f && info.sender.name == hitName){ Kills+=1; Debug.Log(info.sender.name+"=="+hitName); } Debug.Log (info.sender.name+" has "+Kills+" kills"); } }
and the script for the sword:
using UnityEngine; using System.Collections; public class hitEnemy : MonoBehaviour { public Rigidbody swordPos; public PhotonView pv; private PhotonView myPhotonView; public string pNAME; //public int kills; // Use this for initialization void Start () { myPhotonView = PhotonView.Get(this); } // Update is called once per frame void Update () { this.rigidbody.MovePosition(swordPos.position); //this.rigidbody.position(swordPos.position); transform.position = new Vector3(swordPos.position.x,swordPos.position.y, swordPos.position.z); this.rigidbody.MoveRotation(swordPos.rotation); this.rigidbody.freezeRotation = true; //Debug.Log (kills+myPhotonView.viewID); } void OnCollisionEnter(Collision hit){ this.rigidbody.freezeRotation=true; this.rigidbody.MovePosition(swordPos.position); this.rigidbody.MoveRotation(swordPos.rotation); transform.position = new Vector3(swordPos.position.x,swordPos.position.y, swordPos.position.z); if(hit.gameObject.tag == "Player") { pv = hit.collider.GetComponent<PhotonView>(); //attacker = hit.collider.t //pNAME = Attacker.sender.name; myPhotonView.RPC("findSender", PhotonTargets.All); //Debug.Log(ha.sender.name+" sent hit"); //player.RPC("meleeHit", PhotonTargets.AllBuffered, 1.0f); if(pv.viewID-3 != myPhotonView.viewID) pv.RPC("meleeHit", PhotonTargets.AllBuffered, 1.0f, pNAME); } } [RPC] void findSender(PhotonMessageInfo Info){ pNAME=Info.sender.name; } }
basically what i'm looking for is this result:
me wrote:Sword hits player
sword sends player swordID
player recieves hit, hp-=damage
player sends [RPC] to all swords
if(sword.viewID == swordID)
kills+=1;
0