What is wrong with this "if &&" script?

I have a basic cube (enemy) and sphere (hammer), both of which have rigidbodies attached. I have a script attached to the sphere so it follows the mouse cursor.

My overall intention is, if I hover the sphere over the enemy and click the left button, it will stun the enemy for a duration.

If I attach this script to the enemy:

function OnTriggerEnter (other : Collider) 
{
     if(other.tag == "sphere")
    	{
    	Debug.Log ("Stun");
 		}
    
}

Then when I hover the sphere over the enemy, the log will output correctly. However, if I try to add an && like so:

function OnTriggerEnter (other : Collider) 
{
     if(Input.GetMouseButtonDown(0)) && if(other.tag == "sphere")
    	{
    	Debug.Log ("Stun");
 		}
    
}

I get BCE0043: Unexpected token: &&

What am I doing wrong?

You are closing the if statement before &&, and using another if inside if logical checking.

 if((Input.GetMouseButtonDown(0)) && (other.tag == "sphere")){

try this,

if(Input.GetMouseButtonDown(0) && other.tag == “sphere”)

the && evaluates to a bool, so you could do this as well,

bool result = Input.GetMouseButtonDown(0) && other.tag == “sphere”;
if(result) {}

or even have a function

bool question() {
return Input.GetMouseButtonDown(0) && other.tag == “sphere”;
}

if(question()) {}

Public Bool question;
Public Bool result;

Best thing to do is attach a script to an empty game object and test if it works e.g.

if (input.getMouseButtonDown(0) {

question = true;

{

Then you will see it work in the inspector, it’s cool things like that and debug.log that will save you a lot of time and a lot of headache’s.