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
1
Question by Pierre 1 · Dec 10, 2011 at 05:45 AM · variablemonodevelop

2 small questions about scripting

Hello,

I am using MonoDevelop, and I have 2 small questions :

  • Why sometimes MonoDevelop allows me to shrink a function (with the small - / + in the left margin) and sometimes not ?

  • Is there a way to have a variable name containing a variable ? For example, I need to get characteristics from a character database, and I would like to store them into this kind of variable : static var Toughness_5:int (with 5 = id of the character)

Thank you,

Pierre

Comment
Add comment · Show 4
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 syclamoth · Dec 10, 2011 at 05:54 AM 0
Share

This is two different questions, one of which is significantly more complex than the other. Can you explain a little better what you mean by that variable thing? Do you want the variable name to depend on some other value?

The usual object-oriented way of doing this is to have 5 different characters, and to just use

 character5.toughness

ins$$anonymous$$d of having a whole bunch of different things which do almost the same thing as each other.

avatar image Pierre 1 · Dec 10, 2011 at 08:00 AM 0
Share

Well, I think in PHP it works like this :

for ($i=0, $i<10, $i++)

{

$name = "variable_"+$i;

$$name = "myvalue_"+$i;

}

And I shall have :

$variable_1 = myvalue_1

$variable_2 = myvalue_2

etc.

I just want to know how it works in unity to have this " $$name "

avatar image Eric5h5 · Dec 10, 2011 at 08:03 AM 1
Share

99.9% of the time you should use arrays or other collections ins$$anonymous$$d of trying to literally use "toughness_5" and so on as variable names.

avatar image Pierre 1 · Dec 10, 2011 at 09:13 AM 0
Share

$$anonymous$$$$anonymous$$h I guess you are right, I will try to think about it. I'll close this question, and I'll hope I'll find a solution for shrinking my functions ^^

1 Reply

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

Answer by Aralox · Dec 10, 2011 at 12:51 PM

Hi there, Im not sure about the first question, but im guessing if you save your scripts and reopen them with monodevelop you should be able to fold (use +/-) on all your functions.

Aso for your second question, read up on arrays, sounds like just what you need - eg have a toughness array, where you can access toughness[5] (or loop through the array, etc).

If you want a really good, thoroughly explained introduction to scripting, check out the walker bro's tutorials.

Good luck :)

Comment
Add comment · Show 1 · 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 Pierre 1 · Dec 10, 2011 at 01:53 PM 0
Share

Even after saving, I cannot fold some functions. What is strange is that I can hide some of them, but not all (about 20%).

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

6 People are following this question.

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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How do i call on variables from other scripts? 2 Answers

How to associate monodevelop with unity3d 4.5.2 ? 1 Answer

GameObject.name to string 2 Answers

Assigning current color to a variable for fade out (C#) 0 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