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 Canbey06 · Dec 11, 2016 at 06:27 PM · errorvoidsymbol

Please Help "error CS1525: Unexpected symbol `void'''

I'm new to C# :) I cant speak wery well english because ı'm Turkish :P I can't start my game Unity3D says "All complier error have to be fixed" My codes:

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

 public class Karakter : MonoBehaviour {

 public float hiz,maxHiz,ziplamaGücü;
 public bool yerdemi,ciftZipla;
 public int can, maxCan, havuc, altin;
 public GameObject[] canlar;
 public Text Altinmiktar, Havucmiktar;
 public AudioClip[] sesler;
 Rigidbody2D agirlik; Animator anim;

 void Start () {

     anim = GetComponent<Animator> ();
     agirlik = GetComponent<Rigidbody2D> ();
     can = maxCan;
     canSistemi ();

 }

 void Update () {

     Altinmiktar.text = " " + altin;
     Havucmiktar.text = " " + havuc;

     if (Input.GetKeyDown (KeyCode.R)) {
         Application.LoadLevel (Application.loadedLevel);
     }

     //////////ZIPLAMA//////////
     if (Input.GetKeyDown (KeyCode.UpArrow)) {
         if (yerdemi) {
             agirlik.AddForce (Vector2.up * ziplamaGücü);
             ciftZipla = true;
         } else {
             if (ciftZipla) {
                 ciftZipla = false;
                 agirlik.AddForce (Vector2.up * ziplamaGücü);
             }
         }
     }
     if (Input.GetKeyDown (KeyCode.W)) {
         if (yerdemi) {
             agirlik.AddForce (Vector2.up * ziplamaGücü);
             ciftZipla = true;
         } else {
             if (ciftZipla) {
                 ciftZipla = false;
                 agirlik.AddForce (Vector2.up * ziplamaGücü);
             }
         }
     }
     if (Input.GetKeyDown (KeyCode.Space)) {
         if (yerdemi) {
             agirlik.AddForce (Vector2.up * ziplamaGücü);
             ciftZipla = true;
         } else {
             if (ciftZipla) {
                 ciftZipla = false;
                 agirlik.AddForce (Vector2.up * ziplamaGücü);
             }
         }
     }
     /////////ZIPLAMA///////////
     if (can <= 0) {
         olme ();
     }
 }

 void FixedUpdate(){
     float h = Input.GetAxis("Horizontal");
     agirlik.AddForce (Vector3.right * h * hiz);
     anim.SetFloat ("Hiz", Mathf.Abs (h));
     anim.SetBool ("Yerde", yerdemi);


     if (h > 0.1f) {
         transform.localScale = new Vector2 (1, 1);

     }
     if (h < 0.1f) {
         transform.localScale = new Vector2 (-1, 1);

     }

     if (agirlik.velocity.x > maxHiz) {
         agirlik.velocity = new Vector2 (maxHiz, agirlik.velocity.y);
     }
     if (agirlik.velocity.x < -maxHiz) {
         agirlik.velocity = new Vector2 (-maxHiz, agirlik.velocity.y);
     }
 }

 void olme(){
     Application.LoadLevel (Application.loadedLevel);
 }

 void OnCollisionEnter2D (Collision2D nesne){
     if (nesne.gameObject.tag == "Tuzak") {
         can -= 1;
         agirlik.AddForce (Vector2.up * ziplamaGücü);
         GetComponent<AudioSource> ().PlayOneShot (sesler[3]);
         GetComponent<SpriteRenderer> ().color = Color.red;
         Invoke ("Duzelt", 0.5f);
         canSistemi ();
     }
 } 

 }
 

 void canSistemi(){
 for (int i = 0; i < maxCan; i++) {
     canlar [i].SetActive (false);
 }
 for (int i = 0; i < can; i++) {
     canlar [i].SetActive (true);
 }
 }

 void Duzelt(){
     GetComponent<SpriteRenderer> ().color = Color.white;
     } 

 void OnTriggerEnter2D (Collider2D nesne) {
 if (nesne.gameObject.tag == "Havuc") {
     havuc++;
     GetComponent<AudioSource> ().PlayOneShot (sesler[1]);
     Destroy (nesne.gameObject);

 }

 if (nesne.gameObject.tag == "Altin") {
     altin++;
     GetComponent<AudioSource> ().PlayOneShot (sesler[1]);
     Destroy (nesne.gameObject);

 }
 if (nesne.gameObject.tag == "Can") {
     if (can != maxCan) {
         can++;
         canSistemi ();
         GetComponent<SpriteRenderer> ().color = Color.green;
         GetComponent<AudioSource> ().PlayOneShot (sesler[2]);
         Invoke ("Duzelt",0.5f);
         Destroy (nesne.gameObject);
     }

 }

 }

 }

 }

And my error is: Assets/Kodlar/Karakter.cs(117,0): error CS1525: Unexpected symbol `void'

Please help mee :)

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
0
Best Answer

Answer by TBruce · Dec 11, 2016 at 07:38 PM

Hi @Canbey06,

I have fixed and tested your script and it no longer has errors (for me to test I had to change all occurrences of ziplamaGücü to ziplamaGucu as ü is an unrecognized character on my system).

You also had some extra curly braces which I remove. I also created references for the following

 gameObject.GetComponent<AudioSource> ()
 gameObject.GetComponent<SpriteRenderer> ()

in the Start() function because you were calling them frequently. Please forgive me for changing the formatting of your code as it helps me read easier. Below is your updated class

 using System.Collections;
 using System;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class Karakter : MonoBehaviour
 {
     public float hiz ,maxHiz, ziplamaGücü;
     public bool yerdemi, ciftZipla;
     public int can, maxCan, havuc, altin;
     public GameObject[] canlar;
     public Text Altinmiktar, Havucmiktar;
     public AudioClip[] sesler;
     Rigidbody2D agirlik; Animator anim;
 
     AudioSource audioSource;
     SpriteRenderer spriteRenderer;
 
     void Start ()
     {
         anim = GetComponent<Animator> ();
         agirlik = gameObject.GetComponent<Rigidbody2D> ();
         audioSource = gameObject.GetComponent<AudioSource> ();
         spriteRenderer = gameObject.GetComponent<SpriteRenderer> ();
         can = maxCan;
         canSistemi ();
     }
 
     void Update ()
     {
         Altinmiktar.text = " " + altin;
         Havucmiktar.text = " " + havuc;
         if (Input.GetKeyDown (KeyCode.R))
         {
             Application.LoadLevel (Application.loadedLevel);
         }
 
         //////////ZIPLAMA//////////
         if (Input.GetKeyDown (KeyCode.UpArrow))
         {
             if (yerdemi)
             {
                 agirlik.AddForce (Vector2.up * ziplamaGücü);
                 ciftZipla = true;
             }
             else
             {
                 if (ciftZipla)
                 {
                     ciftZipla = false;
                     agirlik.AddForce (Vector2.up * ziplamaGücü);
                 }
             }
         }
 
         if (Input.GetKeyDown (KeyCode.W))
         {
             if (yerdemi)
             {
                 agirlik.AddForce (Vector2.up * ziplamaGücü);
                 ciftZipla = true;
             }
             else
             {
                 if (ciftZipla)
                 {
                     ciftZipla = false;
                     agirlik.AddForce (Vector2.up * ziplamaGücü);
                 }
             }
         }
 
         if (Input.GetKeyDown (KeyCode.Space))
         {
             if (yerdemi)
             {
                 agirlik.AddForce (Vector2.up * ziplamaGücü);
                 ciftZipla = true;
             }
             else
             {
                 if (ciftZipla)
                 {
                     ciftZipla = false;
                     agirlik.AddForce (Vector2.up * ziplamaGücü);
                 }
             }
         }
 
         /////////ZIPLAMA///////////
         if (can <= 0)
         {
             olme ();
         }
     }
 
     void FixedUpdate()
     {
         float h = Input.GetAxis("Horizontal");
         agirlik.AddForce (Vector3.right * h * hiz);
         anim.SetFloat ("Hiz", Mathf.Abs (h));
         anim.SetBool ("Yerde", yerdemi);
 
         if (h > 0.1f)
         {
             transform.localScale = new Vector2 (1, 1);
         }
 
         if (h < 0.1f)
         {
             transform.localScale = new Vector2 (-1, 1);
         }
 
         if (agirlik.velocity.x > maxHiz)
         {
             agirlik.velocity = new Vector2 (maxHiz, agirlik.velocity.y);
         }
 
         if (agirlik.velocity.x < -maxHiz)
         {
             agirlik.velocity = new Vector2 (-maxHiz, agirlik.velocity.y);
         }
     }
 
     void olme()
     {
         Application.LoadLevel (Application.loadedLevel);
     }
 
     void OnCollisionEnter2D (Collision2D nesne)
     {
         if (nesne.gameObject.tag == "Tuzak")
         {
             can -= 1;
             agirlik.AddForce (Vector2.up * ziplamaGücü);
             audioSource.PlayOneShot (sesler[3]);
             spriteRenderer.color = Color.red;
             Invoke ("Duzelt", 0.5f);
             canSistemi ();
         } 
     }
 
     void canSistemi()
     {
         for (int i = 0; i < maxCan; i++)
         {
             canlar [i].SetActive (false);
         }
 
         for (int i = 0; i < can; i++)
         {
             canlar [i].SetActive (true);
         }
     }
 
     void Duzelt()
     {
         spriteRenderer.color = Color.white;
     } 
 
     void OnTriggerEnter2D (Collider2D nesne)
     {
         if (nesne.gameObject.tag == "Havuc")
         {
             havuc++;
             audioSource.PlayOneShot (sesler[1]);
             Destroy (nesne.gameObject);
         }
 
         if (nesne.gameObject.tag == "Altin")
         {
             altin++;
             audioSource.PlayOneShot (sesler[1]);
             Destroy (nesne.gameObject);
         }
 
         if (nesne.gameObject.tag == "Can")
         {
             if (can != maxCan)
             {
                 can++;
                 canSistemi ();
                 spriteRenderer.color = Color.green;
                 audioSource.PlayOneShot (sesler[2]);
                 Invoke ("Duzelt",0.5f);
                 Destroy (nesne.gameObject);
             }
         }
     }
 }
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

96 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

Related Questions

Please help! Public Void unexpected, school project! 1 Answer

I need someone to help me: error CS1525: Unexpected symbol `void' 0 Answers

Keyword 'void' cannot be used in this context, cant figure out what to do 1 Answer

IEnumerator, Unexpected symbol? 3 Answers

Unexpected symbol `void' 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