Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by gnirts · Aug 19, 2014 at 07:25 PM · raycastmouseeventclick

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?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image smoggach · Aug 19, 2014 at 08:57 PM 1
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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);
            }
        }
    }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

Clicked object is stored in a variable? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges