Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by snizkorod · Sep 24, 2015 at 09:46 PM · mousebeginnerscriptingbasics

Scripting Approach to Mouse interaction

Hello,

I'm a complete newbie to Unity 3d and would appreciate feedback to my ideas. I've looked at the unity tutorials, documentation, and many resources to find how to deal with mouse based object selection. While i understand HOW to select an object, im unsure what a good approach is to manage my scripts and data once i select the object i want. Let me back up a bit...

I'm prototyping a 3d isometric gamesimilar to pillars, BG II etc. (i know they arent 3d, but just to get a reference). I will be using the mouse (or touch) to interact with the world and with enemies. For example, im a wizard character and click on an enemy to see their extended stats in a tooltip, Then i click behind them to move, and finally click on a spell and click the enemy to cast it. How should i approach this problem of making sure i know what im clicking on and when it's appropriate to do what action.

My ideas are:

  1. A singular delegate event system that tracks clicks that objects can subscribe to. I would raycast to the mouse (with a Raycastall[] or something) and figure out what's being clicked. Im left with the problem of dealing with scattered code and passing information of the previously clicked object around.

  2. I'd implement an interface solution iPointerClickHandler on Every clickable object i care about in the game. I would then pass the gameObject to a static singleton click manager that keeps track of what's been clicked (in a list or something) and using a bunch of if statements call the necessary functions that way. 3.

  3. I'm not sure how to do this in C# as i come from a javascript node background, but something along the lines of async callbacks with CustomGameObject.onClick( args, 'function to perform', callback); I would use tags to figure out the type of object clicked and use my clicker function to perform necessary actions then continue with the game state via callbacks

Please let me know if one of these approaches is straightforward or if there's another, easier way to accomplish what im trying to do. Thank you very much!

Comment
Add comment · Show 2
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 snizkorod · Sep 24, 2015 at 10:15 PM 0
Share

I'm going with option 2 because it makes the most sense to me for the time being. I'll check back later and reevaluate my approach if someone has feedback

avatar image hexagonius · Sep 25, 2015 at 12:00 PM 0
Share

I'd go with 2 too.

0 Replies

· Add your reply
  • Sort: 

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

29 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make my flashlight move with the mouse movement? 0 Answers

I need help with learning... 1 Answer

Press the button play music in the next scene. 1 Answer

how to make a objesc follow the mouse in the 3d world,how to make a object follow the mouse on the 3d world 0 Answers

First person shooter : Leaning! 2 Answers


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