Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
avatar image
0
Question by Madswint · Jul 11, 2014 at 09:28 PM · javascriptarraymouseright click

I need advice on how to make a right click system similar to runescapes?

I am not asking for any code.

What I'm looking for is advice on how to do a right clicking system like runescapes. The only ways I can think of how to do this, is make a script for every clickable object in the game, but that would be a HUGE waste of space. Obviously this is not how I should do it.

The thing is, when you right click nothing / the ground, it should say nothing and only with a close button, but when you right click lets say a store keeper, there should be options like Talk, Store, Quest, Close. How can I make a system that detects what options the clicked object has, then puts it into an array? If any expert at Unity code could explain how this could be achieved, I would be incredibly grateful. Such a small thing is just being a huge problem for me to solve without wasting space. Thank you!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Loius · Jul 11, 2014 at 09:51 PM

 public class Clickable : MonoBehaviour {

   public virtual string[] Options { get { return new string[0]; } }
   public virtual void HandleClick() {
   }
 }
 
 public class Shopkeeper : Clickable {
   public override string[] Options { get { return base.options.Concatenate(new string[]{"Sell","Buy"}; } }
   public override void HandleClick() {
     DisplayShopMenu();
   }
 }
 
 ...
 
 public class PlayerInput : MonoBehaviour {
   void Update() {
     if ( Input.GetKeyDown(KeyCode.Mouse1) ) {
       RaycastHit rch = new RaycastHit();
       if ( Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition, out rch) ) { // this line is wrong, needs more arguments 
 or something
          Clickable c = rch.collider.GetComponent<Clickable>();
          if ( c ) c.HandleClick();
          else HandleUnclickable();
       }
     }
   }
 }

Keyword: Inheritance.

Comment
Add comment · Show 2 · 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
avatar image Madswint · Jul 11, 2014 at 09:59 PM 0
Share

Would you be able to write it in Js?

avatar image Loius · Jul 13, 2014 at 06:59 AM 1
Share

":" becomes "extends", "void Name()" becomes "function Name()", "Type Name()" becomes "function Name() : Type", "Type variable" becomes "var variable : Type", "base" becomes "super"

i don't know if get/set works in unityscript. they're called 'properties', which will help searching for a fix if they don't. they can also just be rewritten as functions; that's basically all they are.

also search for 'convert cs to unityscript/javascript' because there are more questions about that than there are humans

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

Trying to instantiate random enemy prefab from array 3 Answers

How to get an array of sprite arrays to work (javascript)? 2 Answers

Error creating 5-dimensional array 1 Answer

Array.Push() for Vector3[] or how to add items to Vector3 array without knowing index 1 Answer

Help converting this to C# - a few issues 3 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