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 Christian.Tucker · Aug 21, 2013 at 03:47 PM · function updateunderstanding logic

Not understanding [RPC]

(Edit for bump)

Alright, so I wrote a script for playerHealth and I'm trying to update it so each player over the network will have their own health, but I'm running into the problem where on Client A, I'll have 100 health, and my enemy will have 70 health, but on Client B, we will both have 100 health.

Just not understanding the RPC I guess, I tried using (networkView.isMine) on it, but that didn't work as the networkView is owned by the server. I just don't really know what I'm doing here, how would I make it update.

Lets just say for instance this scripts name is HealthManager and the variable is myHealth, just for an example.

==============================

I was asked for some code, so here's what I have, although, there isn't any RPCs because I'm trying to understand how to use them.

 using UnityEngine;
 using System.Collections;

 public class PlayerStatistics : MonoBehaviour {
     
     bool enabled = false;
     
     //~~Variables Start
     public int currHealth, maxHealth;
     //~~Variables End
     
     void Awake() {
         enabled = true;
     }
     
     // Use this for initialization
     void Start () {
         if(enabled) {
             maxHealth = 100;
             currHealth = maxHealth;
         }
     }
     
     // Update is called once per frame
     void Update () {
         if(enabled) {
             
         }
     }
     
     void OnGUI() {
         if(enabled) {
             GUI.Box (new Rect(20, 20, Screen.width / 3, 30), "Health: " + currHealth + "/" + maxHealth);
         }
     }
 }




here's the code I use to do combat

 using UnityEngine;
 using System.Collections;
 
 public class PlayerCombat : MonoBehaviour {
     
     bool enabled = true;
     
     //~~Variables Start
     public GameObject enemyTarget;
     PlayerStatistics enemyStats;
     //~~Variables End
     
     void Awake() {    
         enabled = true;
     }
     
     // Use this for initialization
     void Start () {
         if(enabled) {
 
         }
     }
     // Update is called once per frame
     void Update () {
         if(enabled) {
             Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
             RaycastHit hit;
             
             if(Input.GetButton("Fire2")) {
                 if(Physics.Raycast (ray, out hit, 100)) {
                     if(hit.collider.tag == "Player") {
                         if(hit.collider.gameObject != gameObject) {
                             Debug.Log ("Clicked other player");
                             enemyTarget = hit.collider.gameObject;
                         } else {
                             Debug.Log ("Clicked self, not targetting");
                         }
                     }
                 }
             }
             if(enemyTarget != null) {
                 enemyStats = enemyTarget.GetComponent<PlayerStatistics>();    
                 if(Input.GetKey(KeyCode.F)) {
                     enemyStats.currHealth -= 10;
                 }
             }
         }
     }
     
     void OnGUI() {
         if(enabled) {
             if(enemyTarget != null) {
                 GUI.Box (new Rect((Screen.width / 3) + (Screen.width / 3), 20, Screen.width / 3, 30), "Enemy Health: " + enemyStats.currHealth + "/" + enemyStats.maxHealth);
             }
         }
     }
 }
Comment
Add comment · Show 7
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
avatar image whydoidoit · Aug 21, 2013 at 03:48 PM 0
Share

Can you post some code?

avatar image Christian.Tucker · Aug 21, 2013 at 04:11 PM 0
Share

I posted it, although there are not any RPCs in it, because that's what I'm questioning / trying to understand

avatar image Christian.Tucker · Aug 22, 2013 at 12:00 AM 0
Share

Bump Please, still needing help

avatar image Benproductions1 · Aug 22, 2013 at 02:27 AM 0
Share

Stop bumping. It clogs up the comment section and helps no one!

avatar image Benproductions1 · Aug 22, 2013 at 02:29 AM 0
Share

You describe a specific problem related to RPC's, then you say you are not using RPC's and post code without RPC's. If you want to understand RPC's, look it up. There are plenty of very good explanations out there.

I also suggest you do some studying on networking to get a hold of the jargon :)

Show more comments

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

17 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

Related Questions

Help me change the code to work with Physics 2D 0 Answers

gameObject not destroyed after reaching desired coordinates. 1 Answer

How to access variable from another function? 2 Answers

Function not executing 1 Answer

Fixing my post processes in my game 0 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