Search Unity

Please fix compile errors before creating new script components.

Discussion in '2D' started by Marrell, Jul 20, 2016.

  1. Marrell

    Marrell

    Joined:
    Jul 19, 2016
    Posts:
    9
    Yo mates I am complete retard at Unity and scripting .I've been doint a 2D Roguelike tutorial and when the scripting part comes in at part 5, when I have to drag the script I made following the tutorial, I get the error : "Please fix compile errors before creating new script components." I don't know how to fix it, I'm using the newest version of Unity if someone knows the solution pls tell me. And btw I installed Unity on D:\ drive,I don't know why, probably because there is more space on it.



























    :D
     
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    Open up your editor console by pressing CTRL+SHIFT+C if it's not already open. (command shift C for mac i guess?)

    Clear the console if there's a lot of stuff in there by pressing the little "clear" button at the top of the console window.

    You should see one or more red entries in the list. Double click an entry and it should take you to the place in your code where you have an error.

    If it doesn't, or you still don't know how to fix it, please reply with the exact error and line number you're seeing. Please also post any relevant snippets of code or full scripts associated with the error, making sure to use Code Tags if you do.
     
    SakeJoghurt, kelfeh and vakabaka like this.
  3. Marrell

    Marrell

    Joined:
    Jul 19, 2016
    Posts:
    9
    @jeffreyschoch Yo mate does using Visual Studio 2015 makes this problem,I mean can it make problems ?
     
  4. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    No, you may see extra yellow warnings inside visual studio 2015, but otherwise the errors are the same for almost all cases. I use Visual Studio 2015 exclusively and have no problems with compiler errors.
     
  5. Marrell

    Marrell

    Joined:
    Jul 19, 2016
    Posts:
    9
    @jeffreyschoch Mate I don't know,I'm currently learning C# from scratch,and I'm going on vacation soon so I won't ahve time to test wtf is the problem :D
    But I'll try and try until I break something here
     
  6. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    Yo read my first response, what do you see in the console? Where does the error point to? What is the error text in the console?
     
  7. analuciaroeder

    analuciaroeder

    Joined:
    Jan 18, 2017
    Posts:
    2
    Im experiencing the same error. I get this on code:
    8 [CustomEditor(typeof(CreaseShading))]
     
  8. waleedomer227

    waleedomer227

    Joined:
    Mar 1, 2017
    Posts:
    2
    just close your unity project after that open it again it will ask you that have you created your project Back up then click yes problem will solved and you can add a new script easily
     
  9. Zeesy

    Zeesy

    Joined:
    Feb 16, 2017
    Posts:
    5
    I am having the same problem. Using this code:
    Code (CSharp):
    1. public Transform MyPrefab;
    2. private float timer = 0f;
    3.  
    4. void Update() {
    5.     timer += Time.deltaTime;
    6.  
    7.     // Spawn a new block every second
    8.     if (timer > 1f) {
    9.         Instantiate(MyPrefab);
    10.         timer -= 1f;
    11.     }
    12. }
    from here: https://stackoverflow.com/questions/27308031/can-i-loop-a-lot-of-falling-objects-in-unity

    Console error on dragging script to GameObject is
    Assets/OBJECTS/Random_Drop.cs(1,7): error CS1525: Unexpected symbol `Transform', expecting `class', `delegate', `enum', `interface', `partial', or `struct'

    Saving and restarting Unity has the same result.
     
  10. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    If that is your entire script (every line, I Mean).. that won'jt work because it's not properly written.

    Do this, create a "new script" in unity. Open that up, and paste the stuff from your post after the line "public class .. " etc.
    (and erase the second Update() if it's present).
     
    Zeesy and vakabaka like this.
  11. Zeesy

    Zeesy

    Joined:
    Feb 16, 2017
    Posts:
    5
    And it works! Thank you. I am still wrapping my head around the logic and meaning of scripts, your answer helped a lot.

    For reference, here's the full code for making objects fall from the sky (taken from https://stackoverflow.com/questions/27308031/can-i-loop-a-lot-of-falling-objects-in-unity):
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Random_Drop : MonoBehaviour {
    6.  
    7.     public Transform MyPrefab;
    8.     private float timer = 0f;
    9.  
    10.     void Update()
    11.     {
    12.         timer += Time.deltaTime;
    13.  
    14.         // Spawn a new object every second
    15.         if (timer > 1f)
    16.         {
    17.             Instantiate(MyPrefab);
    18.             timer -= 1f;
    19.         }
    20.     }
    21.  
    22.     // Use this for initialization
    23.     void Start () {
    24.      
    25.    }
    26.  
    27. }
     
  12. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Cool - glad ya got it working :)

    Ya, before that was only a snippet, people often exclude the stuff you were missing when they write down code examples, presuming the reader(s) will know how it goes. heh.
     
  13. mostafa_eltazy

    mostafa_eltazy

    Joined:
    Jun 10, 2017
    Posts:
    2
    I will try to upload a video , pleas check cuz I don't even write code and it won't any C# only in Java


    I didn't even open the script I only created it then tried to added to the
     

    Attached Files:

  14. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    @mostafa_eltazy : if you wrote in this thread, because you got the same error as the thread title, I can tell you that you have to be more specific, and you have to look at what the errors are. If you're still confused when you read the actual errors from the console, make a thread describing your problem. "Must fix compile errors" is a general statement, could mean anything is wrong. :)
     
  15. mostafa_eltazy

    mostafa_eltazy

    Joined:
    Jun 10, 2017
    Posts:
    2
    Thanx for responding really , the thing is unity send me this massage and I didn't even write any thing in the script
    All I did was
    create a c# file (without making any change in it's code or even opening it)

    Trying to add it as a component to to my character and then the error massage shows
    , I don't what is wrong exactly I even uninstalled unity and RE-installed several times
    And the same thing happens every time .
     
  16. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Well, if there's no code in the file, there's no reason to add it to anything , for starters.
    Did you rename the file after it was made? It says "new" but if you made it, then it was unselected, then you changed its name.. that means its name won't match the script (class name inside). Plus, I wouldn't name a script "new" personally. Maybe like "NewScript" would be better, as 'new' is a keyword in the language.
     
  17. adadjissoarnold

    adadjissoarnold

    Joined:
    Nov 20, 2017
    Posts:
    1
    // Converted from UnityScript to C# at http://www.M2H.nl/files/js_to_c.php - by Mike Hergaarden
    // Do test the code! You usually need to change a few small bits.

    using UnityEngine;
    using System.Collections;

    public class conveerted : MonoBehaviour {

    @script RequireComponent(CharacterController);

    int vitesseDeplacement= 5;
    int saut= 4;
    int gravite= 20;
    Vector3 directionDeplacement = Vector3.zero;

    CharacterController joueur;
    int joueur = GetComponent<CharacterController>();

    void Update (){

    directionDeplacement.z = Input.GetAxisRaw("Veritcal");
    directionDeplacement.x = Input.GetAxisRaw("Horizontal");

    }



    where is error please help me
     
  18. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
  19. jonesty07

    jonesty07

    Joined:
    Jan 20, 2018
    Posts:
    1
    I've got the same problem

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    public class NewBehaviourScript : MonoBehaviour {

    public Text BPS;
    public Text Charactor;
    public Text scoreDisp;

    public float BPS = 0;
    public float Charactor = 0;
    public float score = 0;


    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    scoreDisp.txt = "score: " + score;


    }
    }

    Anyone know why this doesn't work?
     
  20. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    This is a very general message. What is your error exactly? Did you rename the script in Unity & forget to update the class name in the file/script? Or something else?
     
  21. azadealmasi

    azadealmasi

    Joined:
    Feb 4, 2018
    Posts:
    1
    Hi, Im experiencing the same error. I get this erorr and i cant fix it :( photo_2018-02-04_17-46-13.jpg
     
  22. ernestoraezue61

    ernestoraezue61

    Joined:
    Dec 1, 2017
    Posts:
    1
    I get this error :line 27 character 9 need to match with the source.
    this is the code: Getways(doc.SelectNode("/osm/node));
     
  23. WJOcelot

    WJOcelot

    Joined:
    Jan 18, 2019
    Posts:
    1
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class rootmove : MonoBehaviour {
    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {
    transform.Translate(Input.GetAxis("Horizontal") * Time.deltatime, 0f, 0f);

    }
    }
    do you know what is wrong with this?
     
  24. zaisha_khan

    zaisha_khan

    Joined:
    May 21, 2019
    Posts:
    1
    Can someone help me also my code is this

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.EventSystems;

    public class moveCar : MonoBehaviour, IPointerUpHandler, IPointerDownHandler
    {
    bool isPointerDown = false;
    float carSpeed = 0;
    public virtual void OnPointerUp(PointerEventData p)
    {
    isPointerDown = false;
    }
    public virtual void OnPointerDown(PointerEventData p)
    {
    isPointerDown = true;
    }
    public float accelarateCar()
    {
    if (isPointerDown == true)
    {
    carSpeed += 0.1f;
    }
    else
    {
    carSpeed = 0;
    }
    return carSpeed;
    }
    }
    and my error is
    upload_2019-5-21_6-43-35.png
     

    Attached Files:

  25. wellgippo

    wellgippo

    Joined:
    Sep 28, 2020
    Posts:
    3
    HELP! NOT WORKING.



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

    public class Player : MonoBehaviour
    {
    public float speed;

    private Rigidbody2D rb;
    private Vector2 moveInput;
    private Vector2 moveVelocity;

    void Start()
    {
    rb = GetComponent<Rigidbody2D>();
    }

    void Update()
    {
    moveInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
    moveVelocity = moveInput.normalized * speed;
    }

    void FixedUpdate();
    {
    rb.MovePosition(rb.position + moveVelocity* Time.fixedDeltaTime);
    }
    }
     
  26. BABIA_GameStudio

    BABIA_GameStudio

    Joined:
    Mar 31, 2020
    Posts:
    497
    void FixedUpdate();
    should be
    void FixedUpdate()

    There not be a ; on this line.
    Also, you shouldn't be necroing a topic that was last posted in a year ago, especially when it is not related to your issue. Create your own topic to ask for help.
    Is a completely unhelpful explanation of your problem. You will find you get more help if you put in the effort to explain the problem, and post the actual error message you receive.
    Use code tags when posting code.
    More people will help you in the future if you appear to put some effort into your post.
     
    eses likes this.
  27. Jackismad

    Jackismad

    Joined:
    Apr 5, 2021
    Posts:
    1
    I'm having the same error :( this is the code
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    public class NewBehaviourScript : MonoBehaviour {
    public Gameobject UIobject;
    public Gameobject cube;
    // Start is called before the first frame update
    void Start() {
    4
    {

    void OnTriggerEnter(Collide enter)
    {
    if (other.tag == "player")
    {
    UIObject.SetActive(True);
    }
    }
    // Update is called once per frame
    void Update()

    }

    void OnTriggerExit(Collider other)
    {
    UIObject.SetActive(false);
    Destroy(cube);
    }

    }
    can some1 help I need this to work for a text trigger! :(
     
  28. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    Please note that you are hijacking this thread with code that's nothing to do with 2D either (it's UI and 3D physics). Please post scripting issues in the scripting forum as well as using code-tags and not plain-text.

    At least attempt to follow what your error itself is saying. I can see at least one error which is using "Collide"; there's no such type and it should be "Collider". The actual error should be telling you that.