- Home /
Question by
KuPAfoo · Dec 23, 2013 at 03:22 AM ·
photonrespawnconnectinghitpoints
[Photon] Connecting to updated variables
I've created a script that recognizes when a player is dead. However, at the moment you must re-connect to respawn. When a new player connects to the server, all player's HP is full. How can I view HP that's already been edited? Yes... I have created this script from scratch.
using UnityEngine;
using System.Collections;
public class PVP : MonoBehaviour {
public GameObject sword;
private PhotonView myPhotonView;
public Transform health;
public float hpWidth;
public Transform player;
public Transform swordW;
public Transform sheildW;
public Transform swordS;
public Transform sheilds;
// Use this for initialization
private void Start () {
hpWidth = health.localScale.x;
player.renderer.enabled = true;
//swordS.renderer.enabled = true;
swordW.renderer.enabled = true;
sheildW.renderer.enabled = true;
myPhotonView = PhotonView.Get(this);
//this.myPhotonView.RPC("spawnHP", PhotonTargets.AllBuffered);
}
public float speed=0;
// Update is called once per frame
private void Update () {
if(hpWidth<=0.0f)
{
this.player.renderer.enabled = false;
swordS.renderer.enabled = false;
swordW.renderer.enabled = false;
sheildW.renderer.enabled = false;
sheilds.renderer.enabled = false;
this.rigidbody.collider.enabled = false;
swordW.rigidbody.collider.enabled = false;
}
}
private void OnGUI () {
if(this.hpWidth<=0.0f){
if (GUI.Button (new Rect (10,10,150,100), "Respawn")) {
this.myPhotonView.RPC("spawnHP", PhotonTargets.AllBuffered);}
//swordS.renderer.enabled = true;
//swordW.renderer.enabled = true;
//sheildW.renderer.enabled = true;
//myPhotonView = PhotonView.Get(this);
}
}
void OnCollisionEnter(Collision collision){
rigidbody.velocity = new Vector3(0, 0, 0);
if(collision.gameObject.tag == "weapon")
Debug.Log ("i'm Hit");
this.myPhotonView.RPC("success", PhotonTargets.AllBuffered);
if(collision.gameObject == sword)
Debug.Log ("Hit by sword");
if(collision.gameObject.tag == "Player")
Debug.Log ("Colliding player(s)");
if(collision.gameObject.name == "aCube")
Debug.Log ("CollidingPlayer + Box");
if(collision.gameObject.name == "Plane")
Debug.Log ("HIT the floor");
}
void OnCollisionStay(Collision collision){
//if(collision.gameObject.tag == "aSword")
//transform.renderer.enabled = false;
//if(collision.gameObject.tag == "weapon")
//Debug.Log ("ON the floor");
}
void OnCollisionExit(Collision yea){
//transform.renderer.enabled = true;
// Debug.Log ("EXIT");
}
[RPC]
private void spawnHP(){
health.transform.localScale = new Vector3(8.0f, 0.6000001f, 0.5f);
hpWidth = health.localScale.x;
player.renderer.enabled = true;
swordW.renderer.enabled = true;
sheildW.renderer.enabled = true;
this.rigidbody.collider.enabled = true;
swordW.rigidbody.collider.enabled = true;
}
[RPC]
private void success(){
if(hpWidth>0.0f){
hpWidth-=0.5f;
health.transform.localScale -= new Vector3(0.5f, 0, 0);}
else{
player.renderer.enabled = false;
swordS.renderer.enabled = false;
swordW.renderer.enabled = false;
sheildW.renderer.enabled = false;
sheilds.renderer.enabled = false;
}
health.transform.localScale = new Vector3 (hpWidth, 0.6000001f, 0.5f);
//this.renderer.enabled = false;
//health.transform.Translate(2.0f, 0.6000001f, 0.5f);//when attacked my health changes
}
}
Comment
Your answer
Follow this Question
Related Questions
Respawn Photon player 0 Answers
Help! My respawn script isn't working! (Answered) 4 Answers
How to make my character change his location when he collides with an object 1 Answer
Random Spawning Question 2 Answers
Trying to make a checkpoint script 3 Answers