- Home /
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);
}