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 /
avatar image
0
Question by BBSA · Feb 19, 2011 at 10:16 PM · variablesmultipleoptions

Variable Selector

i remember there being a variable that would allow you to select the options you want... that wasnt very descriptive but ill go further into detail. Once i drag my script onto a game object and than look into the inspector and i should see all of my variables. i want to be able to click one and select different options. as in example, if i was to create a weapon script and i didnt want to create multiple scripts for melee and range instead i could just click the variable and than select melee or range. I know that im probably not answering this question quite clearly but i just cant remember what it is.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by BinaryCaveman · Feb 19, 2011 at 11:02 PM

You might be looking for an enum.

The Standard Assets/Character Controllers/Sources/Scripts/MouseLook.cs script makes use of these.

alt text

To declare an enum like in the Mouse Look script, use this (C#):

 public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
 public RotationAxes axes = RotationAxes.MouseXAndY;

and as also in the Mouse Look script, you can use if statements to check the current value of the enum:

 if (axes == RotationAxes.MouseXAndY)
      // do something
 else if (axes == RotationAxes.MouseX)
      // do something else
 else
      // do something else

For JavaScript, it's pretty similar. See this answer for more info.

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 Jessy · Feb 19, 2011 at 11:11 PM 0
Share

This good info was posted while I was posting. I guess I'll keep my answer up because my example more closely fits the specific example in the question, not that it matters much, but it could help to clarify.

avatar image BinaryCaveman · Feb 19, 2011 at 11:19 PM 0
Share

I agree. I was just giving a simple example of how enums are being used in Unity.

avatar image
1

Answer by Jessy · Feb 19, 2011 at 11:08 PM

I think you're talking about an enum. Yes?

import UnityEngine.Debug;

enum Attack {Melee, Range} var attack : Attack;

function Start () { Log(attack == Attack.Melee ? "Melee Attack!" : "Range Attack!"); }

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

No one has followed this question yet.

Related Questions

Does Quality Level remain between scenes? 1 Answer

Difficulty Calling Variables from other scrtipts 1 Answer

Passing a set of variables from one script to another 3 Answers

How to use a script on multiple gameobjects, then change a variable for one of them, not the other. 3 Answers

iTween ValueTo not working 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