Raycasting on specific colliders

Hi,

I’ve placed a touch script to a plane with a mesh collider. It’s basically a raycasthit function to get feedback everytime the mouse clicks on the plane. It works but I just noticed that when I create another plane, there’s feedback to that plane as well even when I didn’t add the script to that object.

How do I make that script unique to only that one plane?

The idea I’m going for is create 2 planes with separate unique scripts. e.g “One plane with script to move horizontally and another plane with a script to move vertically”

Here’s a snippet:

	var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
	
	if (Input.GetMouseButtonDown (0))  //Returns true during the frame the user touches the object
	{
		if (Physics.Raycast (ray, hit, 100)) 
		{
			print("jump");
		}
	}

Thanks in advance.

-Hakimo

Whoops nevermind, got the scripts contained to a plane using Tags :wink:

Yeah Tags will get you there, but I also recommend searching on Raycast and Layers within Unity docs…very useful for grouping objects by collision and raycast detection (or ignoring same) behavior.

Yeah the raycast function takes a layermask as a parameter to tell it specifically what layer to cast the ray to.

here: