Quick question:
I’m working on a Tower Defense game. I’m using a trigger - called “Construction Trigger” - to make sure I don’t build turrets in the paths of creeps.
I have the screen-to-world conversion code for the mouse. What I’m trying to do is detect if the point that’s hit falls inside of the trigger. If it is, a tower can be instantiated, otherwise, I can play an annoying sound - all things I know how to do.
…Just not the part where I check if a point falls inside of a trigger.
Current Mouse->World code:
var TowerPrefab : GameObject;
var distance : int;
function OnMouseUp ()
{
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if( Physics.Raycast( ray, hit, distance ) )
{
Instantiate( TowerPrefab, hit.point, Quaternion.identity );
}
}