Please fix compile errors before creating new script components.

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.

:smile:

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.

3 Likes

@LiterallyJeff Yo mate does using Visual Studio 2015 makes this problem,I mean can it make problems ?

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.

@LiterallyJeff 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 :smile:
But I’ll try and try until I break something here

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?

Im experiencing the same error. I get this on code:
8 [CustomEditor(typeof(CreaseShading))]

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

I am having the same problem. Using this code:

public Transform MyPrefab;
private float timer = 0f;

void Update() {
    timer += Time.deltaTime;

    // Spawn a new block every second
    if (timer > 1f) {
        Instantiate(MyPrefab);
        timer -= 1f;
    }
}

from here: Can I loop a lot of falling objects in unity? - Stack Overflow

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.

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).

2 Likes

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 Can I loop a lot of falling objects in unity? - Stack Overflow):

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

public class Random_Drop : MonoBehaviour {

    public Transform MyPrefab;
    private float timer = 0f;

    void Update()
    {
        timer += Time.deltaTime;

        // Spawn a new object every second
        if (timer > 1f)
        {
            Instantiate(MyPrefab);
            timer -= 1f;
        }
    }

    // Use this for initialization
    void Start () {
     
   }
 
}

Cool - glad ya got it working :slight_smile:

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.

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

@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. :slight_smile:

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 .

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.

// Converted from UnityScript to C# at Convert unity javascript (unityscript) to C# - 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();

void Update (){

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

}

where is error please help me

You should look at the console for the error before you post here.

However, I believe you have an issue with RequiredComponent, look at this example: Unity - Scripting API: RequireComponent

Also, you’re missing a closing brace ‘}’ for the script.

Last, but not least, please refer to this page for how to post code on the forums in the future: Using code tags properly

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?

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?