There are two gameObjects in the game: Player1 and Player2. They both share a script InputReader and a script DoSomething.
public class InputReader : MonoBehaviour{
//properties
public GameObject yourObj;
public bool inputIsReceived;
public bool hasScriptAttached;
public bool willReceiveJoystick1Input;
public bool willReceiveJoystick2Input;
/*public GetInput(){
inputIsReceived = false;
}*/
public void CheckIfScriptIsAssigned(){
//Checks the object name and assigns proper Input
//Player1
if(gameObject.name == "Player1"){willReceiveJoystick1Input = true;
Debug.Log("Will receive Joystick 1 Input");
}
//Player2
if(gameObject.name == "Player2"){willReceiveJoystick2Input = true;
Debug.Log("Will receive Joystick 2 Input");
}
}
public void CheckInput (){
if(willReceiveJoystick1Input){
if(Input.GetKeyDown(KeyCode.A)){
Debug.Log ("Input player1 received");
}
}
if(willReceiveJoystick2Input){
if(Input.GetKeyDown(KeyCode.B)){
Debug.Log ("Input player2 received");
}
}
}
//public aGetInput x = new aGetInput();
void Start (){
//CheckIfScriptIsAssigned();
}
void Update (){
//CheckInput();
}
}
What do I write in DoSomething script, so I could use any function from InputReader script at any time? Like x.CheckInput() in update and x.CheckIfScriptIsAssigned() in start. Really at a loss here ._.