Problems using an or (II) inside of an if statement.

Hey guys,

When I run my script with a single variable such as (== “Capsule1I”) inside of my if statement everything works the way I intend. When I attempt to use (== “Capsule1I” || “Capsule8I”), I always get true out, no matter what is detected by the linecast. Is there a problem with my syntax or method? There are a total of 4 possible capsules that I would like to use (== “Capsule1I” || “Capsule8I” || “Capsule16I” || “Capsule24I”). Is this possible or do I need to try something else?

var hit : RaycastHit;
var line : RaycastHit;
var cp : boolean = false;

function Update(){

	if(Input.GetMouseButtonDown(0) && collider.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), hit, Mathf.Infinity)){

		if(Physics.Linecast(Vector3(0,7.25,-5), Vector3(0,7.25,5), line)){
			if( == "Capsule1M"){
				cp = true;
				Debug.Log("check position true");
    		else {
    			cp = false;
    			Debug.Log("check position false");

I think the syntax of your IF statement may be wrong, try this:

if( == "Capsule1M" || == "Capsule2M" ){
     //other stuff

each “OR” ( || ) operator needs full syntax.

if you want it to be a bit easier to read then I would store the gameObjects name in a instance variable:

var name : String =;

if( name == "Capsule1M" || name == "Capsule2M" ){