Skip to main content
Added check for canClick
Source Link
basklein
  • 416
  • 2
  • 9

The code is a bit messy, but I think you'll want to set "mouseClicked" to false when you right-click. So in the Input.GetMouseButton(1) if statement:

if (Input.GetMouseButton(1)) {
    Debug.Log ("Pressed secondary button.");
    rightClicked = true;
    mouseClicked = false;
}

If you then want to fire the bullet again, you'll want to add the reverse in the left-click if statement. So you'll want to set "rightClicked" to false there.

At the moment it's continuously aiming because you're never telling it to stop doing so.

Edit:

As you said in your comment, you want to only be able to click the left mouse button once, then ignore it.

That can be achieved by adding a new boolean to check whether or not the left mouse button can be clicked. As displayed here:

private bool canClick = true;

if (canClick) {
        if (Input.GetMouseButtonDown (0)) {
            Debug.Log ("Left Mouse Button was pressed");
            moveSpeed = 0f;
            if (sr.sprite == sp1) { // if the spriteRenderer sprite = sprite1 then change to sprite2
                sr.sprite = sp2;
            }
            mouseClicked = true; //register that the mouse has been clicked and the sprite is changed to sprite2

            rightClicked = false;                
            canClick = false;
        }
    }

The code is a bit messy, but I think you'll want to set "mouseClicked" to false when you right-click. So in the Input.GetMouseButton(1) if statement:

if (Input.GetMouseButton(1)) {
    Debug.Log ("Pressed secondary button.");
    rightClicked = true;
    mouseClicked = false;
}

If you then want to fire the bullet again, you'll want to add the reverse in the left-click if statement. So you'll want to set "rightClicked" to false there.

At the moment it's continuously aiming because you're never telling it to stop doing so.

The code is a bit messy, but I think you'll want to set "mouseClicked" to false when you right-click. So in the Input.GetMouseButton(1) if statement:

if (Input.GetMouseButton(1)) {
    Debug.Log ("Pressed secondary button.");
    rightClicked = true;
    mouseClicked = false;
}

If you then want to fire the bullet again, you'll want to add the reverse in the left-click if statement. So you'll want to set "rightClicked" to false there.

At the moment it's continuously aiming because you're never telling it to stop doing so.

Edit:

As you said in your comment, you want to only be able to click the left mouse button once, then ignore it.

That can be achieved by adding a new boolean to check whether or not the left mouse button can be clicked. As displayed here:

private bool canClick = true;

if (canClick) {
        if (Input.GetMouseButtonDown (0)) {
            Debug.Log ("Left Mouse Button was pressed");
            moveSpeed = 0f;
            if (sr.sprite == sp1) { // if the spriteRenderer sprite = sprite1 then change to sprite2
                sr.sprite = sp2;
            }
            mouseClicked = true; //register that the mouse has been clicked and the sprite is changed to sprite2

            rightClicked = false;                
            canClick = false;
        }
    }
Source Link
basklein
  • 416
  • 2
  • 9

The code is a bit messy, but I think you'll want to set "mouseClicked" to false when you right-click. So in the Input.GetMouseButton(1) if statement:

if (Input.GetMouseButton(1)) {
    Debug.Log ("Pressed secondary button.");
    rightClicked = true;
    mouseClicked = false;
}

If you then want to fire the bullet again, you'll want to add the reverse in the left-click if statement. So you'll want to set "rightClicked" to false there.

At the moment it's continuously aiming because you're never telling it to stop doing so.