0
\$\begingroup\$

I keep getting the following error when i try to drag and drop a script to my gameobject:

enter image description here

I have made sure that both my Script name and the class name is : Soldier as you can see:

public class Soldier : MonoBehaviour
{
    public int Rank;
}

So my question is what have i done wrong?

\$\endgroup\$
3
  • \$\begingroup\$ Will you restart Unity and try again? From your screenshot and code, seems nothing wrong. \$\endgroup\$
    – modernator
    Commented Jun 14, 2018 at 10:11
  • \$\begingroup\$ @modernator ive done that 5 times not luck :( \$\endgroup\$ Commented Jun 14, 2018 at 10:13
  • \$\begingroup\$ Well then did you try with different file name and class name? Still have same error? \$\endgroup\$
    – modernator
    Commented Jun 14, 2018 at 10:25

1 Answer 1

2
\$\begingroup\$
  1. Fix compiler error.
  2. Make sure you have "using UnityEngine;" in your namespace.
  3. make sure you have the same names for classname and filename

I assume your file has a big "I" instead of a small "L" or a special character.

to check it paste both, the Filename here and then the Class name here:

https://www.textmagic.com/free-tools/unicode-detector

Compare for special characters. (red)

i != í for example

You might have accidently pushed ´ or ` something before pushing the i button, resulting in a different class name than file name.

To make it 100% sure copy and paste the classname to the filename.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .