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.
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.
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
But I’ll try and try until I break something here
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
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’
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).
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 () {
}
}
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.
@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.
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.
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?