• 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 Salter1998 · Oct 24, 2013 at 09:21 AM · componentsscritping

Scripting Help

Okay this is my problem, I'm a semi-noob at Unity and I've come across a problem when I'm scripting. It's kind of hard to explain.

I watch tutorials on Unity for example how to make player float, adding footstep sounds and so on. But I have a problem with any script type I make...

For example, when I drag a floating script into my FPS player, I don't get the options that all people do like changing the force with a little slider button under the component. And today, I took a script from this forum which was how to add footstep noises every time I move (walk) and the guy said once you drag the script into the player. You can then have the option to add in an audio file... but there's no spot for that kind of thing.

Like in this picture, under script, I never ever get the options alt text

I always get this kind of thing, without any extra optionsalt text

So what I'm asking is, how do people get options with their script under the components tab because I'm copying the scripts exactly and nothing works for me...

If anyone can answer this for me, they're fantastic because I can defiantly enhance my game if I know what the problem is. Cheers. P.S apologies for the small image

capture.jpg (8.8 kB)
captaure.jpg (11.0 kB)
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 btb200 · Oct 24, 2013 at 09:34 AM 0
Share

Check if your class has public variables. Can you post code of that script?

1 Reply

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

Answer by vexe · Oct 24, 2013 at 09:35 AM

Make sure your variables access specifiers are public.

in C#, you have to explicitly use the public keyword when you declare a variable:

 public float f;

If you declare it without an access specifier, it's then private by default (as if you put private in front of it):

 float f; // same as private float f;

In JS however, it's the opposite, if you don't specify an access specifier, it's public by default, and if you wanted it to be private, you have to explicitly tell it to:

 var f : float; // same as public var f : float;

A variable is only visible in the inspector if it was public, so make sure the stuff you need isn't private

private means that other classes can't access your current class variable.

What if, you wanted a private variable, other classes can't have access to, but yet let it be visible in the inspector?

you add the SerializeField attribute before your variable declaration, like:

 [SerializeField] private float f; // C#

and

 @SerializeField
 private var f : float; // JS


Comment
Add comment · Show 3 · 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 Salter1998 · Oct 25, 2013 at 11:51 AM 1
Share

Thank you very much, but if I follow the tutorials on YouTube precisley (remembering to type public). It's just irritating. I don't understand

avatar image vexe · Oct 25, 2013 at 11:53 AM 0
Share

@Salter1998: You're welcome. Yes, that's a good point. I hate doing that as well (very) - That's why I think it would be wiser to learn program$$anonymous$$g first, and then hop back to Unity, things will be a lot easier, and make lots more sense. If you have any more Qs feel free to ask. And if my answer helped, give it the tick ;-)

avatar image meat5000 ♦ · Oct 25, 2013 at 11:55 AM 0
Share

Post your script, Ill try it in my IDE

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Couldn't attach any components to 3D model Prefab 1 Answer

Animation curves of sub-objects not accessible 1 Answer

Associate a data object to Monobehaviours with generic 0 Answers

Disable Component of all child GameObjects 2 Answers

Animator data exactly the same, but animator doesn't work 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