Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges