I want to trigger an event based on alignment

I want to trigger an event when there is another object behind the object that I selected with mouse. Can you help me with the functions that I need and how to apply them. Thanks.

You should put a short and explanatory title and ask your question in the body.

Pretty fuzzy question. If you mean anywhere behind, then you can use Transform.InverseTransformPoint() on all potential game objects and take a look 'z' values. If you mean approximately directly behind, you can Raycast backwards. Or depending on your situation, you could compare the angle of the forward vector to a ray between potential objects and the selected object.

@rubertbu, wouldn't it be much efficient to just compare the distance, rather than doing a whole matrix multiplication in order to do the same? (Vector3.Distance not Transform.InverseTransformPoint)

The thing is the objects are always changing. The one I select and the one that is behind it according to my fps position. So I need something that is valid for all cases.

1 Answer

1

You should make a script with the following code:
But before you do that, MAKE SURE you make a trigger and attach this script to it

var objectBehind : GameObject; //this is the object that will be behind your other object

function OnTriggerEnter (Other : Collider){

if(Other.gameObject.tag == "yourTag") {//tag the other object to a tag and change "yourTag" to that tag

//Do something, implement your code here or animation or whatever
 
   }


}

Please read the question before you answer

I was just trying to help, @Benproductions1

Posting an answer that has nothing to do with the question doesn't help anyone.