- Home /
Ontriggerenter and InvokeRepeating problem
Hello, this is my code:
// variable to ensure that InvokeRepeating only runs once.
private var RespawnState : boolean = false;
function OnTriggerEnter (other : Collider) {
if (other.tag == "Player"){
// continue if we are the server...
if(Network.isServer) {
if(RespawnState == false) {
RespawnState = true;
InvokeRepeating ("Spawn", 1, 20); // start Invoke
}
}
}
}
function Spawn(){
var instantiatedenemy = Network.Instantiate (...);
}
InvokeRepeaing should only be executed if we are the server, however, if we are not the server (we are client) InvokeRepeating is also executed.
What i am doing wrong?
Thank you, and sorry for my english. :P
Answer by Sheppard_25 · Oct 04, 2013 at 09:02 PM
Ok, finally i know why is this happening, hard to explain in english... let's try...
There's a game with 2 players (host & client1). If client1 enters trigger zone, Network.isServer will be equal to false, and all will be OK. But when the player of client1 (mesh) has entered the trigger in the game's host, Network.isServer will be equal to true.
So, although Network.isServer is equal to false being client, the InvokeRepeating will be executed by our player (mesh) in the game's host.
I know it's a little confusing, hope someone could traslate it better, maybe it can be useful for someone.