Get mouse left and right in the same time ?

I want to ask about the Mouse Input.
I made 2 target point : control by mouse position and arrow key. Target1 will shoot when Left click, and target2 will shoot when right click.
Here is my code :

ray0 = Camera.main.ScreenPointToRay (Input.mousePosition);
ray1 = Camera.main.ScreenPointToRay (new Vector2 (target2.transform.position.x * Screen.width,target2.transform.position.y * Screen.height));


target1.transform.position.x = Input.mousePosition.x/Screen.width;
target1.transform.position.y = Input.mousePosition.y/Screen.height;

translation : float = Input.GetAxis (“Vertical”) * target2SpeedextraSpeed;
translation2 : float = Input.GetAxis (“Horizontal”) * target2Speed
extraSpeed;

target2.transform.Translate (0, translation*Time.deltaTime, 0);// Move translation along the object’s y-axis

target2.transform.Translate (translation2*Time.deltaTime, 0, 0);


if (plane.Raycast(ray0,dist0))
{
if (Input.GetMouseButtonDown(0))
{
var hitPoint0=ray0.GetPoint(dist0);
bulletMcopyL.GetComponent(bulletM_setting).targetP= hitPoint0; // script of direction bullet shooting
}
}
if (plane.Raycast(ray1,dist1))
{
if (Input.GetMouseButtonDown(1))
{
var hitPoint1=ray0.GetPoint(dist1);
bulletMcopyR.GetComponent(bulletM_setting).targetP= hitPoint1; // script of direction bullet shooting
}
}

My problem is : it’s not working right when I click left and right mouse in the same time. The direction of target1 is same with direction of target2.:frowning: . How can I solve this problem ?
My code is right when just left click or right click.

Thank you for you help. :stuck_out_tongue:
P/S : Sorry about my English.

if((Input.GetMouseButtonDown(0))(Input.GetMouseButtonDown(1))) { } This may work :smile:

Thank you. But it’s still not work.
I think my plane.Raycast has problem :frowning: !??

Input.GetMouseButton(0) Input.GetMouseButton(1)

Yes, I checked.
But this code isn’t in Update. I tried to bring Input.GetMouseButton to another script (Update) , it didn’t work too.

function Update()
{
if ( Input.GetMouseButton(0))
isShoot1 = true;
if (Input.GetMouseButtonUp(0))
isShoot1 = false;

if (Input.GetMouseButton(1))
isShoot2 = true;
if ( Input.GetMouseButtonUp(1))
isShoot2 = false;
}

function shoot()
{

var plane0 = new Plane(Vector3(0,0,-1),1);
var plane1 = new Plane(Vector3(0,0,-1),5);
var dist0:float;
var dist1:float;
var ray0 = Camera.main.ScreenPointToRay (Input.mousePosition);
var ray1 = Camera.main.ScreenPointToRay (new Vector2 (target2.transform.position.x * Screen.width,target2.transform.position.y * Screen.height));

if (plane0.Raycast(ray0,dist0))
var hitPoint0=ray0.GetPoint(dist0);

if (plane1.Raycast(ray1,dist1))
var hitPoint1=ray1.GetPoint(dist1);

if(isShoot1 == true )
{
bulletMcopyL = Instantiate(bullet[1],bullet[1].transform.position,Quaternion.identity);
bulletMcopyL.GetComponent(bulletM_setting).targetP= hitPoint0;
}

if( isShoot2== true)
{
bulletMcopyR = Instantiate(bullet[0],bullet[0].transform.position,Quaternion.identity);
bulletMcopyR.GetComponent(bulletM_setting).targetP=hitPoint1;
}

}

you can trow away the mousebutton up and just do a mouse buttonDown

if ( Input.GetMouseButtonDown(0))
isShoot1 = true;

and set it to false here:

if(isShoot1 == true )
{
bulletMcopyL = Instantiate(bullet[1],bullet[1].transform.position,Quaternion.identity);
bulletMcopyL.GetComponent(bulletM_setting).targetP = hitPoint0;
isShoot1=false;
}

Thanks, it’s still not work.
:((

You’re not calling shoot(). You’re just setting variables.

Also, please use code tags, they make things much easier to read.

Thanks, but I just write to example the main. I wrote that it’s run right when I just shoot left or right mouse :slight_smile: , but if I shoot both left and right in the same time, it’s not right.
I will try to use code tags .

If you’re not posting your actual code how do you expect us to help with it?