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 Oudaiesty · Apr 17, 2010 at 03:02 PM · networkingbattle-system

Battle system (networking upgrade)

Alright I have a battle system that would work wonders in a single player point of view but i'm not certain that it would work in a Networking point of view.

It starts here

PlayerController.js:

This function call is inside an update loop.

function AttackProcedure() { if(!Input.GetAxis("Toggle")) { if(Input.GetAxis("Fire1")) {

         Command("Attack");
         currentState = true;
     }

         currentState = false;
 }

} function Command(cmd : String ) { if(!currentState) gameObject.SendMessage(cmd);

} /......./break Then it goes to commandline.js:

private var cPlayer : Status; private var cAction : ActionController; var cDamage : DamageInformation;

function Awake() { cAction = gameObject.GetComponentInChildren(ActionController); if(!cAction) Debug.Log("No connection to action controller");

 //~ cDamage = GetComponent(DamageInformation);
 //~ if(!cDamage)
     //~ Debug.Log("No connection to damage controller");

 cPlayer = GetComponent(Status);
 if(!cPlayer)
     Debug.Log("Cannot connect to player");

}

function Update () { CoolDownTimer(); } function CoolDownTimer() {

} function CheckStats(dmg : DamageInformation) {

} function ApplyElement(dmg : DamageInformation) {

} function Attack() { var atkPower = Random.Range(1.5, 2.0); cDamage = new gameObject.FindObjectOfType(DamageInformation); CheckStats(cDamage); cDamage.attackType = "p"; cDamage.physicalPercent = 1.0; cDamage.magicPercent = 0.0; cDamage.elementalType = "null"; cDamage.elementalPercent = cPlayer.mElementalPercent; cDamage.attackRadius = cPlayer.mAttackRadius; cDamage.damage = cPlayer.mStrength * atkPower; cAction.attacking = true; cDamage.cost = 1; cDamage.fatigue = 0.001; ApplyElement(cDamage); Debug.Log("Total damage: " + cDamage.damage); cAction.Commence(cDamage);

}

/....../break Then it sends the newly filled out information to the actioncontroller.js:

private var cPlayer : Status; var pController : PlayerController; var attacking : boolean = false; var Damage; var loc : Vector2; var bCol : Transform; var sCol : Transform; function Awake() { pController = transform.parent.GetComponent(PlayerController); if(!pController) Debug.Log("Cannot find player controls");

 cPlayer = transform.parent.GetComponent(Status);
 if(!cPlayer)
     Debug.Log("Cannot connect to player");

}

function Update () { loc.x = cPlayer.mPosition.x; loc.y = cPlayer.mPosition.y; } function OnTriggerEnter(other : Collider) {

 var Opponent = other.gameObject.GetComponent(Status);

     Opponent.ApplyDamage(Damage);

}

function Commence(dmg : DamageInformation) {
if(cPlayer.coolDown < cPlayer.endurance) { if(!cPlayer.holdForCoolDown) { if(attacking) {

                 gameObject.collider.radius = dmg.attackRadius;
                 gameObject.collider.center.x = pController.atkDirection.x * dmg.attackRadius;
                 gameObject.collider.center.y = pController.atkDirection.y * dmg.attackRadius;
                 cPlayer.coolDown += dmg.cost * cPlayer.fatigue;
                 cPlayer.fatigue += dmg.fatigue;
                 gameObject.collider.radius = 0;

         }
         attacking = false;
         Damage = dmg;
     }
 }

}

/...../ break this script resizes a collider and when that collider hits a player it sends Damage to the opponents status for calculation.

I figure that I should send the players status to everyone on the server but when should I do it? and what changes should I make to make it work on networking?

All files have been linked properly via their variables so I didn't include them in these snippets

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Wiki

Answer by Christian Stewart · Dec 09, 2010 at 08:02 PM

You will want to make these be RPC Calls.

Sorry for a short answer, but I have very little time right now.

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
avatar image
0

Answer by YeOldeSnake 1 · Jan 07, 2011 at 11:41 AM

Add @RPC above each function then call them with

networkView.RPC("My function",RPCMode.All,"my parameters"); 

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

No one has followed this question yet.

Related Questions

I need help translating Javascript to C# 0 Answers

Unity networking tutorial? 6 Answers

Networking Player Nametag 1 Answer

Client can't spawn GameObject's 0 Answers

Network traffic and bandwidth usage standards 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