I have 2 players, with the same script attached to them. P1 with ScriptA and P2 with ScriptA. One of the function is highlight a player on tap, then if player is highlighted, enable pass.
This is how my code looks like.
else if (gesture.pickObject != null)
{
if (gesture.pickObject.transform == soccerBall.GetComponent<BallBehaviourCS>().myOwner)
{
if (soccerBall.GetComponent<BallBehaviourCS>().myOwner == players [0])
{
players[0].GetComponent <TPCCS>().highlight = true;
players[1].GetComponent <TPCCS>().highlight = false;
}
else if (soccerBall.GetComponent<BallBehaviourCS>().myOwner == players [1])
{
players[1].GetComponent <TPCCS>().highlight = true;
players[0].GetComponent <TPCCS>().highlight = false;
}
}
else if (gesture.pickObject.transform != soccerBall.GetComponent<BallBehaviourCS>().myOwner && gesture.pickObject.gameObject.tag == "Player")
{
Debug.Log ("Player 2: " + players[1].GetComponent <TPCCS>().highlight);
if (gesture.pickObject.transform.GetComponent<TPCCS>().highlight == true)
{
pass (gesture);
}
else
{
gesture.pickObject.transform.GetComponent <TPCCS>().highlight = true;
if(gesture.pickObject.transform == players[0])
{
gesture.pickObject.transform.GetComponent<TPCCS>().highlight = true;
players[1].GetComponent <TPCCS>().highlight = false;
}
else if (gesture.pickObject.transform == players[1])
{
gesture.pickObject.transform.GetComponent<TPCCS>().highlight = true;
players[0].GetComponent <TPCCS>().highlight = false;
}
}
}
There is no error however there is logical error. The correct logic is you must highlight the player first, before passing. First tap highlight, second tap pass.
What happens here is, P2 is highlighted on first tap with P1 as the owner of the ball. Then when P2 tapped the second time, P1 passes the ball to him. However, for P1, on first tap I tap on P1, it highlights and P2 straight away passes the ball to P1, without waiting for the second tap.
Can I know why P2 works but not P1? I really need help over here.
Thanks in advance.