- Home /
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:
- I click on "Set starting position"
- I click on another object on the map
- 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?
I would create a big 'ol collider behind any UI stuff and in front of any game objects. Then i'd attach a script with the collider and have it cast rays into the scene to pick out objects. I'd check out TouchScript if I was you.
Raycast is the best way to pick out objects from the scene and there are loads of plugins out there to facilitate.
Answer by gnirts · Aug 27, 2014 at 08:54 PM
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);
}
}
}
Your answer
Follow this Question
Related Questions
Object Movement via Mouse Click? 3 Answers
Using RayCast to Get Mouse Input 1 Answer
Mouse Click and Spawn object 4 Answers
Detect if object clicked on 2 Answers