Interaction between commands waiting onMouseUp()

Hi,

I’ve a theoretical (and consequently pratical) problem concerning how to manage a specific interaction between some “stuff” in coding.

I instantiate via code (C#) everything in my game but the terrain, main camera and again 3 or 4 other objects; everything else is coded: objects recalling prefs, GUIs, behaviours and so on.

Now… I have a vehicle and I want to set a new route to this vehicle. When you double click on the vehicle a window appears with all vehicle’s data and some buttons to control some actions (start, stop, more info etc.) and 2 “special buttons”: “Set starting point” and “Set ending point”.

I desire the following behaviour:

  1. I click on "Set starting position"
  2. I click on another object on the map
  3. The vehicle now has its starting point set

Please consider that my onMouseUp() function associated on my map objects is as follows:


MapObject OnMouseUp()
{
	if ((Time.time - doubleClickStart) < GlobalVariables.WindowDblClickDelay)
    	{
    		OnDoubleClick();
    		doubleClickStart = -1;
    	}
    	else
    	{
    		doubleClickStart = Time.time;
    	}
    	return this.mapObject;
}

This means that I don't care the exact point where the player will click, but the object (it will bring every info with itself).

I'm not sure how I have to proceed.

What shall I do? Handlers? Listeners? Raycast using?

Ok, I've realized something quite different than your reply still using raycasting.

I’m not sure if the way I acted was as you said (also because my prefab was composed by a lot of sub-objects).

This is quite the way I solved the question:

if (memMouseStart) {
    	if(Input.GetMouseButtonUp(0))
    	{
    		Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    		RaycastHit r = new RaycastHit();
    		if(Physics.Raycast(ray, out r, 1000.0f)){
    			startingPoint = r.point;
    			memMouseStart = !memMouseStart;
    			clickedObjectName = r.collider.gameObject.transform.parent.name);
    		}
    	}
    }