Search Unity

Question it wont compile the code

Discussion in 'Linux' started by mahmoudk1000, Nov 16, 2020.

  1. mahmoudk1000

    mahmoudk1000

    Joined:
    Oct 25, 2020
    Posts:
    5
    im trying to learn game develop but i have this problem i think compiler related
    error mssage "error CS1056: Unexpected character" i got this error for lines that start with private float so any help would be appreciated. thanks
    my code here https://del.dog/tifamygnys

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerController : MonoBehaviour
    6. {
    7. // Start is called before the first frame update
    8. void Start()
    9. {
    10.  
    11. }
    12. private float speed = 20.0f;
    13. private float turnSpeed = 45.0f;
    14. private float horizontalInput;
    15. private float forwardInput;
    16. // Update is called once per frame
    17. void Update()
    18. {
    19. horizontalInput = Input.GetAxis("Horizontal");
    20. forwardInput = Input.GetAxis("Vertical");
    21. // Moves the car forward based on vertical input
    22. transform.Translate(Vector3.forward * Time.deltaTime * speed * forwardInput);
    23. // Rotates the car based on horizontal input
    24. transform.Rotate(Vector3.up * turnSpeed * horizontalInput * Time.deltaTime);
    25. }
    26. }
     
  2. MadWatch

    MadWatch

    Joined:
    May 26, 2016
    Posts:
    112
    I copy pasted this code in a file and it compiles just fine.

    Also, this is not a Linux related question so you shouldn't post it on this forum.
     
  3. mahmoudk1000

    mahmoudk1000

    Joined:
    Oct 25, 2020
    Posts:
    5
    i pasted here cuz i think its related to linux that iam missing some pkg or so as this code doest get compiled it says the error i said before "error CS1056: Unexpected character" for the lines private float * them all also when i googled i saw many people say that there is missing pkg for this error but it was for windows only found not to linux so what is wrong with my setup or with requirements i forget or missed ?! thanks for reposd and help
     
  4. MadWatch

    MadWatch

    Joined:
    May 26, 2016
    Posts:
    112
    Unity embeds its own version of Mono. The compiler is the same for every platform. And a missing package wouldn't cause an error like this.

    Most likely, you have some freaky character in your source file (possibly an invisible one) and the compiler doesn't understand it. Or maybe your file is using a weird encoding. I would recommend configuring your text editor to show all the invisible characters and to encode all the files in UTF8. Even better, use a text editor that can understand the code so it will underline the problematic part.
     
  5. mahmoudk1000

    mahmoudk1000

    Joined:
    Oct 25, 2020
    Posts:
    5
    what text editor you recommend to use ?
     
  6. MadWatch

    MadWatch

    Joined:
    May 26, 2016
    Posts:
    112
    What are you currently using?

    Each developer has his own favorite tool. You will have to find your own.

    For a beginner, I would recommend something basic like Kate or GEdit. I heard good things about Atom and Sublim Text too, but I didn't try those. If you feel nerdy you might want to try Vim.

    There are some more advanced text editor that can analyses the code, highlight problems and help you search the code. Many Unity developers use MonoDevelop or VSCode for this (or Visual Studio on Windows). I heard Atom, Sublim and Vim can also do that if you install the correct plugin, but again, I never tried.

    I used VSCode before. It does the job but it sucks. It's a notorious pain in the ass to set it up and it breaks with each and every update.

    Now I use JetBrain Rider. It's great but it's not free and it has a tone of options and features. Not a tool for a beginner.
     
  7. mahmoudk1000

    mahmoudk1000

    Joined:
    Oct 25, 2020
    Posts:
    5
    iam useing VSCode right now. but gonna rider a try it might help to get over this errors. BTY thanks for your help