- Home /
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
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.
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");
Your answer
Follow this Question
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