I’m trying to create a game where every character has a chance to do damage to his enemy.Every character in my game has a random number generator function and i invoke the random number method every 1.2 seconds so attack will do damage if random number satisfies the character chance.I’m using photon unity network.My problem is when i spawn a character on field it will generate different numbers on machine 1 and machine 2.For example machine 1 generated number 10 , this satisfies the function so it will do damage , but on machine 2 it generated number 50 it didnt satisfy so it didnt do damage.So i want it to generate random number on the machine who spawned the character and to synchronize it on the opponent screen so it will do damage or not.How can i do this ? I can provide any code you need.Sorry for my bad english.
Hi,
From what I understand, you want to have a script that chooses two numbers, one the target, and one the local number. You want the characters to attack if the target and local numbers are the same - right?
Well, this is fairly simple. What you would have to do is first make a coroutine, then wait for 1.2 seconds, and generate two integers, and if they match, attack.
IEnumerator CheckAttack(){
int targetNum = Random.Range(0,10);
int localNum = Random.Range(0,10);
yield return new WaitForSeconds(1.2f);
if(targetNum == localNum){
Attack(); //Run attack code here
Debug.Log("Target number was " + targetNum " + “. Attacking.”);
}else{
Debug.Log(“Cannot attack.”);
}
}
Hope this helps!
-Miggi124