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 ChrisElmore11 · Mar 14, 2016 at 09:17 AM · c#errorscript.

WHAT IS WRONG WITH THIS CODE?

So I am trying to setup a line of code that changes a parameter from 0 to 1 when the W key is pressed down, but I keep getting an error with the symbol "public." I don't know what's wrong. This is my C# code:

using UnityEngine; using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
     if (Input.GetKeyDown(KeyCode.W) public void SetFloat("Forward", 1));

 }

}

Comment
Add comment · Show 6
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 gjf · Mar 12, 2016 at 08:34 PM 0
Share

are you trying to set an animation parameter (using SetFloat())? if so, you'll need to get a reference to it first.

public void blah-blah-blah is how you declare a function, not call one.

your line should look something like this:

 if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.W))
 {
     // do something
 }

the 'do something' part might be (it depends on what you're really trying to do):

 _anim.SetFloat("Forward",1);

where _anim has been set to the animator component.

best advice for you - you might want to spend time with some c# tutorials...

avatar image ChrisElmore11 gjf · Mar 12, 2016 at 10:04 PM 0
Share

Ok... I followed that but and here's my code:

using UnityEngine; using System.Collections;

public class NewBehaviourScript : $$anonymous$$onoBehaviour {

 // Use this for initialization
 void Start () {

 }
 
 // Update is called once per frame
 void Update () {
     if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.W))
     {
         _anim.SetFloat("Forward",1)
     **}**
 }

}

But it's having parsing problems on the symbols surrounded by ** or bold. Also, how do I set up the _anim to the animator component. I will look more into c#.

avatar image Hellium ChrisElmore11 · Mar 14, 2016 at 09:00 AM 0
Share

Semi-colon is missing

avatar image Hellium · Mar 14, 2016 at 09:02 AM 0
Share

@gjf : Friendly re$$anonymous$$der of the FAQ :

FAQ :

What are the guidelines for writing good questions?

We want Unity Answers to become a comprehensive database of questions and answers related to Unity. When you ask your questions, it can be helpful to keep a few things in $$anonymous$$d:

  • Don't post multiple unrelated questions in one post. $$anonymous$$ake separate posts ins$$anonymous$$d, each with one question.

  • Don't write things that will be irrelevant in a few days. Writing that "This is urgent!" will probably not get you faster answers, but it may make people frown at your question.

  • Be specific. If you want specific answers, ask specific questions. If something "doesn't work", write what exactly it does that is wrong.

  • Use specific tags. unity, scripting, editor, etc. are very non-specific tags. Consider using tags that are more specific to your exact question. Tags are case sensitive, so if you can't find the tag you want to use in the drop-down list, try using lower/upper case letters as an alternative. Here is the full list of tags.

  • Break multi-part problems into simpler questions. Ins$$anonymous$$d of posting a question: "How can I make a gui toggle to change the skybox?", post two simpler questions ins$$anonymous$$d: "How can I make a gui toggle?" and "How can I change the skybox?" This way the questions will also be relevant to people who want to make a toggle for something else, or who want to change the skybox based on something else.

Some reasons for getting a post rejected:

  • You haven't provided enough context: we need more information about your problem, relevant code snippets and what you have tried already.

  • There exists duplicate questions with answers if you were to do a search, either on Answers or on the Forum

  • Your question isn't specific enough: asking for a script, asking multiple questions in one post or asking a question that could be either subjective or require extensive discussion (and thus belongs in the Forum)

  • Badly formated question: code needs to be formatted using the 101/010 button, break your post up into several parts so it's understandable what you are asking, and make sure there is a question in your post

  • Asking us to fix your code: more than likely, you simply need to get a better understanding of basic program$$anonymous$$g. Having a look at the Scripting tutorials on the Learn page will help you become more familiar with scripting in Unity

  • Posting about a specific compiling error or NullReferenceException: there is a myriad of these questions with answers already, have a look at those posts to get hints on what could possibly be your issue

avatar image gjf Hellium · Mar 14, 2016 at 05:26 PM 0
Share

@Hellium: thanks, i'm well aware of the FAQ ;)

rather than telling me that, in addition to pointing out the missing semicolon, you might have helped the OP in the update regarding how they set up the animator component reference.

@ChrisElmore11:

in Start() you need to get a reference to the animator component, so add a line like this:

 _anim = GetComponent<Animator>();

and before Start() declare the following:

 private Animator _anim;


avatar image Hellium gjf · Mar 14, 2016 at 05:41 PM 0
Share

When I see a question where the majority of the requirements are not satisfied, I rarely take the time to answer the OP. Especially when there are a thousand of question about the subject, tutorials about the topic on Unity Learn, etc....

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Menu object not responding 0 Answers

"The associated script cannot be loaded." 0 Answers

Unity keeps rejecting my code, even when there are no errors 1 Answer

Can't add Orbital script - "The script needs to derive from MonoBehaviour!" 0 Answers

Cannot convert String to int 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