i need to check which object (playing piece) the user has clicked on...but the problem is the else if block does not seem to detect the mouse input.
sorry i forgot the braces..
void Update () {
if (chance == 1) {
if (Input.GetKeyUp (KeyCode.Space)) {
if (enableInput == true) {
enableInput = false;
markers [0].gameObject.SetActive (true);
markers [1].gameObject.SetActive (false);
markers [2].gameObject.SetActive (false);
markers [3].gameObject.SetActive (false);
a.PlayOneShot (s_Dice);
DiceRoll ();
if (subPlayer == 4 && diceno == 6) {
Vector3 temp;
Vector3 currentPos;
subPlayer -= 1;//3
temp = transform.position;
subplayers1 [0].transform.position = new Vector3 (startingpos1.transform.position.x, -1.8f, startingpos1.transform.position.z);
Invoke ("waitandgo",0.5f);
} else if (Input.GetMouseButtonDown(0) && subPlayer == 3 && diceno == 6) {
//print ("clicked");
//ray = Camera.main.ScreenPointToRay (Input.mousePosition);
//if (Physics.Raycast (ray, out hit))// {
print("Click");
}
}
}
}
}
Answer by TBruce · Jan 07, 2017 at 07:57 PM
You are missing 4 closing braces } which should cause errors. If you just did not add them to your question then please add them to your question.
If I just add 3 closing braces } to the end of your script then this is what your code looks like
void Update ()
{
if (chance == 1)
{
if (Input.GetKeyUp (KeyCode.Space))
{
if (enableInput == true)
{
enableInput = false;
markers [0].gameObject.SetActive (true);
markers [1].gameObject.SetActive (false);
markers [2].gameObject.SetActive (false);
markers [3].gameObject.SetActive (false);
a.PlayOneShot (s_Dice);
DiceRoll ();
if (subPlayer == 4 && diceno == 6)
{
Vector3 temp;
Vector3 currentPos;
subPlayer -= 1;//3
temp = transform.position;
subplayers1 [0].transform.position = new Vector3 (startingpos1.transform.position.x, -1.8f, startingpos1.transform.position.z);
Invoke ("waitandgo",0.5f);
}
else if (Input.GetMouseButtonDown(0) && subPlayer == 3 && diceno == 6)
{
//print ("clicked");
//ray = Camera.main.ScreenPointToRay (Input.mousePosition);
//if (Physics.Raycast (ray, out hit))
{
print("Click");
}
}
}
}
}
}
But the code above will not see the mouse click. You are probably looking for something moe like this
void Update ()
{
if (chance == 1)
{
if (Input.GetKeyUp (KeyCode.Space))
{
if (enableInput == true)
{
enableInput = false;
markers [0].gameObject.SetActive (true);
markers [1].gameObject.SetActive (false);
markers [2].gameObject.SetActive (false);
markers [3].gameObject.SetActive (false);
a.PlayOneShot (s_Dice);
DiceRoll ();
if (subPlayer == 4 && diceno == 6)
{
Vector3 temp;
Vector3 currentPos;
subPlayer -= 1;//3
temp = transform.position;
subplayers1 [0].transform.position = new Vector3 (startingpos1.transform.position.x, -1.8f, startingpos1.transform.position.z);
Invoke ("waitandgo",0.5f);
}
}
}
else if (Input.GetMouseButtonDown(0) && subPlayer == 3 && diceno == 6)
{
//print ("clicked");
//ray = Camera.main.ScreenPointToRay (Input.mousePosition);
//if (Physics.Raycast (ray, out hit))
{
print("Click");
}
}
}
}
i edited it..but it still does not detect the mouse input
I added some debug code to your script so you can see where the problem lies (take a look at the console).
void Update ()
{
if (chance == 1)
{
Debug.Log("chance = " + chance);
if (Input.Get$$anonymous$$eyUp ($$anonymous$$eyCode.Space))
{
Debug.Log("Space key pressed");
if (enableInput == true)
{
Debug.Log("enableInput i true, setting it to false");
enableInput = false;
markers [0].gameObject.SetActive (true);
markers [1].gameObject.SetActive (false);
markers [2].gameObject.SetActive (false);
markers [3].gameObject.SetActive (false);
a.PlayOneShot (s_Dice);
DiceRoll ();
if (subPlayer == 4 && diceno == 6)
{
Debug.Log("subPlayer is equal to 4 and diceno is equal to 6");
Vector3 temp;
Vector3 currentPos;
subPlayer -= 1;//3
temp = transform.position;
subplayers1 [0].transform.position = new Vector3 (startingpos1.transform.position.x, -1.8f, startingpos1.transform.position.z);
Invoke ("waitandgo",0.5f);
}
}
}
else if (Input.Get$$anonymous$$ouseButtonDown(0))
{
Debug.Log("Left mouse button was clicked");
if (subPlayer == 3 && diceno == 6)
{
Debug.Log("subPlayer is equal to 3 and diceno is equal to 6");
//print ("clicked");
//ray = Camera.main.ScreenPointToRay (Input.mousePosition);
//if (Physics.Raycast (ray, out hit))
{
print("Click");
}
}
else
{
Debug.Log("subPlayer must be equal to 3 and diceno must be equal to 6 to enter the block above");
}
}
}
else
{
Debug.Log("is not equal to 1, chance is equal to " + chance + ". chance must be equal to 1 to enter the block above");
}
}
In your original code the following needs to be true to enter the block with the print statement
chance must be equal to 1
the left mouse button needs to be clicked
subPlayer must be equal to 3
diceno must be equal to 6
Your answer
Follow this Question
Related Questions
Adding to List of Nested Classes 1 Answer
C# If string is equal to any in array 2 Answers
If/ElseIf never reaches elseif 0 Answers
The If statement condition is false but the if statement stills executes 1 Answer
If/else statement is always else 1 Answer