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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Le_Spirit · Jan 29, 2015 at 10:51 AM · multiplayerhealth

How do I create a FPS health system such that the damage are calculated globally?

Problem:

I currently got a multiplayer fps set up (w/o photon or other add-ons). When i start the game, the player both spawns and controls a prefab soldier.

So for my player health script:

 #pragma strict
 
 var health: int=100;
 
 function OnGUI() {
     GUI.Box(Rect(Screen.width/2-250,Screen.height/2+80,270,200),
     "<size=24>Health</size><color=orange><size=80>"+Player.health+"</size></color>");
 }
 
 function TakeDamage(Damage:int){
     if(health!=0)
     health-=Damage;
     else
     health=0;
     }
 }

and on the bullet's script:

 function OnTriggerEnter(FPS:Collider){
             FPS.gameObject.GetComponent(PlayerHealth).TakeDamage(Damage);
 }

When I(server side) fire and the bullet collides with the client's capsule collider, health -1 on server's side! Points are also deducted from client's health. After multiple shots fired, the HP doesn't even tally between the 2 sides. What is it that I'm doing wrong?

I suspect that the way i declared health makes it a shared variable between all players. (Is it?)

Also, when the health reduces to 0, I've tried to include Destroy(gameObject). On server side, the player's prefab gets destroyed, but on client's side, the health isnt even 0 yet (and it doesnt get destroyed).

Help please!!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Pie556 · Oct 22, 2021 at 11:51 PM

Now i do belive this is Java or something and i do C# but i can help a tiny bit hopefully, you can change the trigger void On TriggerEnter(Collider coll) { //this is for c# but try and make this go into Java or JavaScript } change that to collision void OnCollisionEnter(Collision Coll) { //Damage code }

and go to whatever you put this script on, go to the collider in it and make sure than is trigger is false if that does not work check if is trigger is set to true otherwise if you have a script saying Trigger and the collider is not a trigger it will cause some problems :) If you are confused on how to add this into Java (Or JavaScript) Than they are soo many tutorials on JS or Java with unity that pro cover this :))

Comment
Add comment · Share
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

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

My Photon health script doesnt work 2 Answers

my lose health script isn't working? 1 Answer

Unity networking tutorial? 6 Answers

Photon Combat script does not work 0 Answers

Can't get Gui Pos on top of Enemy ingame! 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