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 Danibro · Aug 07, 2017 at 07:44 AM · voidunexpected-symbol

Help me fix my code!!

After MonoDevelop giving up and killing itself 30 mins after I got it working by a complete reinstall I gave up and decided to deal with Visual Studio's cluttered and utterly disgusting interface so I could code without errors but now half my code is underlined in red that wasn't a week ago and ugh I don't even know.

I have an unexpected symbol 'void' at line 37 but was at line 46 (magically went away... see what I mean) and Visual Studio doesn't recognize the update part in the void. It does however in my other rotation script. (once again see why I am so confused)

Anyway here is a copy of my script and any fixes would be helpful. (I'm very much a beginner at programming so excuse my bad scripting techniques)

using UnityEngine; using UnityEngine.UI; using System.Collections;

public class PlayerController : MonoBehaviour {

 public float speed;
 public Text countText;
 public Text winText;
 public Keycode ResetKey = Keycode.r;
 public string SceneName = "MiniGame";

 private Rigidbody rb;
 private int count;

 void Start ()
 {
     rb = GetComponent<Rigidbody>();
     count = 0;
     SetCountText ();
     winText.text = "";
 }

 void FixedUpdate ()
 {
     float moveHorizontal = Input.GetAxis("Horizontal");
     float moveVertical = Input.GetAxis("Vertical");

     Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

     rb.AddForce(movement * speed);

 }

}

 void Update () {
 if (Input.GetKeyDown("r"))
 {

    Application.LoadLevel(MiniGame);
 }

} void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Pick Up")) { other.gameObject.SetActive(false); count = count + 1; SetCountText(); } }

 void SetCountText ()
 {
     countText.text = "Count: " + count.ToString ();
     if (count >= 24)
     {
     winText.text = "You Win!";
     }
 }

}

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 SteenPetersen · Aug 07, 2017 at 07:54 AM

You have an extra "}"

use this:

 using UnityEngine; using UnityEngine.UI; using System.Collections;
 
 public class PlayerController : MonoBehaviour {
 
 public float speed;
 public Text countText;
 public Text winText;
 public Keycode ResetKey = Keycode.r;
 public string SceneName = "MiniGame";
 private Rigidbody rb;
 private int count;
 void Start()
 {
     rb = GetComponent<Rigidbody>();
     count = 0;
     SetCountText();
     winText.text = "";
 }

 void FixedUpdate()
 {
     float moveHorizontal = Input.GetAxis("Horizontal");
     float moveVertical = Input.GetAxis("Vertical");
     Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
     rb.AddForce(movement * speed);
 }

 void Update()
 {
     if (Input.GetKeyDown("r"))
     {
         Application.LoadLevel(MiniGame);
     }
 }


     void OnTriggerEnter(Collider other)
     {
         if (other.gameObject.CompareTag("Pick Up"))
         {
             other.gameObject.SetActive(false); count = count + 1; SetCountText();
         }
     }

     void SetCountText()
     {
         countText.text = "Count: " + count.ToString();
         if (count >= 24)
         {
             winText.text = "You Win!";
         }
     }

 }

Should work.

Comment
Add comment · Show 6 · 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 Danibro · Aug 12, 2017 at 10:44 AM 0
Share

Thank you so much for fixing 90% of it that was a $$anonymous$$AJOR help!!

Everything is fixed except this, any idea?

ERROR: The type or namespace name 'keycode' could not be found. are you missing assembly reference? - line 11

If you can fix this your a god and I love you!!

avatar image SteenPetersen Danibro · Aug 12, 2017 at 11:16 AM 0
Share

remove this line from your variables:

 public $$anonymous$$eycode Reset$$anonymous$$ey = $$anonymous$$eycode.r;

hope that helps, remember to mark answer as correct if it does.

avatar image Danibro SteenPetersen · Aug 12, 2017 at 11:38 AM 0
Share

Fixed the keycode thing but now there's this...

It is saying: The name '$$anonymous$$iniGame' does not exist within the current context.

even though it is referenced in the variables??

line 33 in the code below...

using UnityEngine; using UnityEngine.UI; using System.Collections;

public class PlayerController : $$anonymous$$onoBehaviour {

 public float speed;
 public Text countText;
 public Text winText;
 public string SceneName = "$$anonymous$$iniGame";
 private Rigidbody rb;
 private int count;

 void Start()
 {
     rb = GetComponent<Rigidbody>();
     count = 0;
     SetCountText();
     winText.text = "";
 }
 void FixedUpdate()
 {
     float moveHorizontal = Input.GetAxis("Horizontal");
     float moveVertical = Input.GetAxis("Vertical");
     Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
     rb.AddForce(movement * speed);
 }
 void Update()
 {
     if (Input.Get$$anonymous$$eyDown("r"))
     {
         Application.LoadLevel($$anonymous$$iniGame);  - this is the problem line $$anonymous$$inigame is underlined - 
     }
 }
 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.CompareTag("Pick Up"))
     {
         other.gameObject.SetActive(false); count = count + 1; SetCountText();
     }
 }
 void SetCountText()
 {
     countText.text = "Count: " + count.ToString();
     if (count >= 24)
     {
         winText.text = "You Win!";
     }
 }

}

Show more comments

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

111 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 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 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 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 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 avatar image

Related Questions

Unexpected symbol `void' in class, struct, or interface member declaration 1 Answer

"void" error in SceneManager Script 1 Answer

Unexpected symbol `void' 0 Answers

Unexpected Symbol 'void' 1 Answer

Void cannot be used in this context, unexpected symbol expecting `,', `;', 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