Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 mirajose93 · May 10, 2017 at 02:17 PM · networkingprefabtriggers

Affect gameobjects with same script across network

Don't know what would sound like a better title, but what I'm trying to do: I have two game objects on a network that are the same prefab, a host and a client. When a character performs a move there is a script that calls an OnTriggerEnter function that affects the health of the other character on the network. Both characters have the same scripts (Teichac_Control & Combatant_stats). In both scripts there is a few lines of code in the update function:

  if (!isLocalPlayer) {
         return;
     }

The code uses a trigger event because I want the character to lose health according to Damage - Distance. I have this code just to test and see if it works. The problem is that I don't know how to affect the other character object that holds the same script without affecting my local player since I come up with an error along of the lines of "Object reference not set to an instance of an object". I was hoping someone would be able to point me in the right direction.

 void OnTriggerEnter(Collider ene){
     enemy = ene.gameObject;
     InvokeRepeating ("DistDamage", 0.0f, 0.5f);
 }

 void DistDamage(){
     float CHP; //for health
     bool Blk;  //for if statment
     float DB;  //for defense calculation of enemy
     CHP = enemy.GetComponent<Combatant_stats>().CurrHealth;  //current health on enemy
     Blk = enemy.GetComponent<Teichac_Control> ().blockState;  //whether or not they block
     DB = enemy.GetComponent<Teichac_Control>().Stats.Defense; //base block defense

     if (!Blk)
         CHP -= baseDamageDist;
     else
         CHP -= (DB - baseDamageDist);

 } 
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Unity Networking: Object only spawning on the Host client. 2 Answers

Instantiating Multiple Clients into one 2 Answers

UNet changing player prefabs int the network lobby sample. 0 Answers

InvalidCastException when Instantiating with photon (PUN) 2 Answers

Display equipment over network 1 Answer


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