0

I have two scripts in my Unity project: Start.cs and Enemy.cs.I deleted Enemy.cs. I ran the game and it worked fine. Now, I created another script with the same name Enemy.cs. Now Unity is showing a compile error as follows when I run the game:

The namespace '' already contains a definition for 'Enemy'

But the first Enemy script is already deleted. Should I do something like clean up in Unity because it is cached somewhere or any other reason? If I have to clean up, how would I do that?

derHugo
  • 83,094
  • 9
  • 75
  • 115
Kiran Cyrus Ken
  • 379
  • 1
  • 3
  • 17
  • Please use the correct tags! Note that [`unityscript`](https://stackoverflow.com/tags/unityscript/info) is or better **was** a JavaScript flavor like custom language used in early Unity versions and is long **deprecated** by now! As the description of the tag explains this is **not** to be used for just any question related to Unity and script files. – derHugo Jul 13 '21 at 01:59
  • Do you have any other compiler errors? In such case Unity might not have recompiled the code yet. For cleaning up in general have a look e.g. at [Cleaning up and Migrating existing Unity project into new one or another PC](https://stackoverflow.com/questions/56267842/cleaning-up-and-migrating-existing-unity-project-into-new-one-or-another-pc/56267992#56267992) – derHugo Jul 13 '21 at 02:02
  • Did you restart Unity? – Retired Ninja Jul 13 '21 at 02:18
  • @RetiredNinja Yes – Kiran Cyrus Ken Jul 13 '21 at 12:22
  • I was unable to reproduce your error. However if the error is an internal Unity bug, right click next to the scripts and click "Reimport All". If the bug is internal to Unity, this method will kill it. Otherwise the problem is another, in that case I would be curious to see the scripts if you can share them, so i can reproduce the error. – Francesco - FL Jul 13 '21 at 12:55
  • @FreeLearning Turns out it was not a bug. I usually add the scripts in the scripts folder under Assets. But this one had a copy directly in the Assets folder. Thank you for looking into. – Kiran Cyrus Ken Jul 20 '21 at 09:17

1 Answers1

1

If restarting doesn't work, close unity, delete Assembly-CSharp.csproj from the root of your project and then reopen it in unity.

SpicyCatGames
  • 863
  • 7
  • 25