Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

need help with Error CS1525 Unexpected Symbol void?

Discussion in '2D' started by Rycon03, Oct 9, 2018.

  1. Rycon03

    Rycon03

    Joined:
    Oct 8, 2018
    Posts:
    16
    upload_2018-10-8_22-29-8.png
    upload_2018-10-8_22-29-50.png



    Anyone Know anything about this i'm new to unity?
     

    Attached Files:

  2. Rycon03

    Rycon03

    Joined:
    Oct 8, 2018
    Posts:
    16
    Image attached is irrelevant
     
  3. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    You have placed all of your methods outside of the class body:
    Picture1.png
     
    vakabaka likes this.
  4. Rycon03

    Rycon03

    Joined:
    Oct 8, 2018
    Posts:
    16
    So where do I move them to? sim not really good at this stuff.
     
  5. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    line 13 to line 44
     
  6. Rycon03

    Rycon03

    Joined:
    Oct 8, 2018
    Posts:
    16
    Got a bunch of new errors after I moved it. But void error is solved thank you.


    upload_2018-10-9_21-25-46.png
     
  7. Rycon03

    Rycon03

    Joined:
    Oct 8, 2018
    Posts:
    16
     
  8. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    i think this is an error from an other script. Do you have 2 scripts playermoving ? Try to delete this script and make an other with other name
     
  9. Rycon03

    Rycon03

    Joined:
    Oct 8, 2018
    Posts:
    16
    upload_2018-10-9_21-46-14.png Unexpected Symbol end-of-line.
    upload_2018-10-9_21-46-59.png
     
  10. Rycon03

    Rycon03

    Joined:
    Oct 8, 2018
    Posts:
    16
    yup got that one done thank you.
     
  11. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    the last one is missing the } , at the end
     
  12. Rycon03

    Rycon03

    Joined:
    Oct 8, 2018
    Posts:
    16
    upload_2018-10-9_21-53-40.png upload_2018-10-9_21-53-49.png I feel so dumb right now, but im still getting an error.
     
  13. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    transform.localScale make no sense for me :D delete it, at the end
    wait this will not help
     
  14. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    localScale.x = -1;
    transform.localScale = localScale;
    }
    }
     
  15. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    or the line should be:
    localScale.x *= -1;
     
  16. Rycon03

    Rycon03

    Joined:
    Oct 8, 2018
    Posts:
    16
    nope im still getting errors. It just keeps saying unexpected symbol end-of-file
    upload_2018-10-9_22-4-26.png upload_2018-10-9_22-4-37.png
     
  17. Rycon03

    Rycon03

    Joined:
    Oct 8, 2018
    Posts:
    16
    the localscale part i know is fine, its just maybe i didnt do a bracket right.
     
  18. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    the transform.localScale should be in the LateUpdate

    localScale.x *= -1;
    transform.localScale = localScale;
    }
    }
    i think this can be end of the script
     
  19. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    and I whould say, dont use screenshot :D
    you can just insert here the code with code tags
    Code (CSharp):
    1. void LateUpdate () {
    2. //here i am to lazy to type
    3. localScale.x *= -1;
    4. transform.localScale = localScale;
    5. }
    6. }
     
  20. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    copypaste the script here, i will change it then
     
  21. Rycon03

    Rycon03

    Joined:
    Oct 8, 2018
    Posts:
    16
    i posted it but its under moderation for some reason
     
  22. Rycon03

    Rycon03

    Joined:
    Oct 8, 2018
    Posts:
    16
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class movement : MonoBehaviour
    6. {
    7.  
    8.  
    9.     public float moveSpeed = 3f;
    10.     float ve1X;
    11.     float ve1Y;
    12.     bool facingright = true;
    13.     Rigidbody2D rigbody;
    14.  
    15.  
    16.  
    17.     // Use this for initialization
    18.     void Start() {
    19.         rigBody = GetComponent<Rigidbody2D>();
    20.  
    21.     }
    22.  
    23.  
    24.     // Update is called once per frame
    25.     void Update() {
    26.         ve1x = Input.GetAxisRaw("Horizontal");
    27.         ve1y = rigBody.velocity.y;
    28.         rigBody.velocity = new Vector2(ve1X * moveSpeed, ve1Y);
    29.     }
    30.  
    31.  
    32.     void LateUpdate()
    33.     {
    34.         Vector3 localScale = transform.localScale;
    35.         if (ve1X > 0) {
    36.             facingRight = true;
    37.         } else if (ve1X < 0) {
    38.             facingRight = false;
    39.         }
    40.         if (((facingRight) && (localScale.X < 0)) || ((!facingRight) && (localScale.x > 0))) {
    41.             localScale.X = -1;
    42.         }
    43.  
    44.     }
    45.     transform.localScale
    46.  
     
  23. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    Code (CSharp):
    1. void LateUpdate () {
    2. //here i am to lazy to type
    3. localScale.x *= -1;
    4. transform.localScale = localScale;
    5. }
    6. }
    7. }
    i have missed one }
     
  24. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    one } for if, second } for LateUpdate, third } for class
     
  25. Rycon03

    Rycon03

    Joined:
    Oct 8, 2018
    Posts:
    16
    how do i put in my code, every time i put it in it just says its awaiting moderator approval
     
  26. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    copypaste without code tag
     
  27. Rycon03

    Rycon03

    Joined:
    Oct 8, 2018
    Posts:
    16
    whats a code tag?
     
  28. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    copy your script and then just insert it here
     
  29. Rycon03

    Rycon03

    Joined:
    Oct 8, 2018
    Posts:
    16
    i actually cannot put it in with copy paste or inserting it, it just keeps saying that its under moderation. is there any other way i can contact you. like a discord or something
     
  30. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    try private message
     
    Rycon03 likes this.
  31. Rycon03

    Rycon03

    Joined:
    Oct 8, 2018
    Posts:
    16
    nevermind i fixed it. was just missing a bracket diagnol to line 50 and a semicolon. thank you for all your help.
     
  32. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
  33. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class movement : MonoBehaviour
    6. {
    7.  
    8.     public float moveSpeed = 3f;
    9.     float ve1X;
    10.     float ve1Y;
    11.     bool facingRight = true;
    12.     Rigidbody2D rigBody;
    13.  
    14.  
    15.  
    16.     // Use this for initialization
    17.     void Start()
    18.     {
    19.         rigBody = GetComponent<Rigidbody2D>();
    20.  
    21.     }
    22.  
    23.  
    24.     // Update is called once per frame
    25.     void Update()
    26.     {
    27.         ve1X = Input.GetAxisRaw("Horizontal");
    28.         ve1Y = rigBody.velocity.y;
    29.         rigBody.velocity = new Vector2(ve1X * moveSpeed, ve1Y);
    30.     }
    31.  
    32.  
    33.     void LateUpdate()
    34.     {
    35.         Vector3 localScale = transform.localScale;
    36.         if (ve1X > 0)
    37.         {
    38.             facingRight = true;
    39.         }
    40.         else if (ve1X < 0)
    41.         {
    42.             facingRight = false;
    43.         }
    44.         if (((facingRight) && (localScale.x < 0)) || ((!facingRight) && (localScale.x > 0)))
    45.         {
    46.             localScale.x *= -1;
    47.             transform.localScale = localScale;
    48.         }
    49.  
    50.     }
    51. }