Say I have three different gameObjevcts
, each representing rock, paper or scissors. These objects all have a Player
script attached to them. The Player
script has two functions i want to use, MoveSelected()
, MoveNotSeleccted()
. When the function CPUMove()
is called, I want the program to randomly choose one of the three moves. My question is, how do I call a either of the functions fro another script RPS_Game
? I thought of using Invoke() somehow but after trying couple of things with it, I got no where. Can someone please help me out?
public class RPS_Game {
public void CPUMove() {
int rand = Random.Range(1, 3);
if(rand == 1) {
//call MoveSelected() for one of the three Player objects and
MoveNotSelected() for the other two
}
else if(rand == 2) {
//call MoveSelected() for one of the three Player objects and
MoveNotSelected() for the other two
}
else if(rand == 3) {
//call MoveSelected() for one of the three Player objects and
MoveNotSelected() for the other two
}
}
}
Invoke()
method, which isn't mentioned here. One could certainly answer this one usingInvoke()
, but I don't think that would be the best answer to direct users to in this case. \$\endgroup\$