Error: The type or namespace could not be found

Im trying to acces a script in another script and it gives me this error:

message: 'The type or namespace name ‘simpleShooting’ could not be found (are you missing a using directive or an assembly reference?) ’ at: ‘14,9’ source: ‘’

this is the script what needs the other script:

using System.Collections;
using UnityEngine;
using simpleShootingNS; //error here
using itemSpawnerManagerNS;
public class PauseManager : MonoBehaviour
{
    [HeaderAttribute("keybind to enable/disnable pause menu")]
    public KeyCode PauseKeyBind;
    [HeaderAttribute("player character to disnable")]
    public GameObject character;
    [HeaderAttribute("GameObject of pauseMenu to en/disnable")]
    public GameObject pauseMenu;
    [SpaceAttribute("extra scripts that needs to disnable || this will fill in automaticly!")]
    public simpleShooting simpleShooting; // same error here
    public itemSpawnerManager itemSpawnerManager;

    bool isPaused;

    void Start()
    {
        simpleShooting = GameObject.Find("SCRIPTS").GetComponent<simpleShooting>(); // same erros at <simpleShooting>
        itemSpawnerManager = GameObject.Find("SCRIPTS").GetComponent<itemSpawnerManager> ();
    }

    void Update()
    {
        if (Input.GetKeyDown(PauseKeyBind))
        {
            isPaused = !isPaused;
        }
        if (isPaused)
        {
            //disnable player character
            character.SetActive(false);
            //enable gm of paus menu
            pauseMenu.SetActive(true);
            //time scale
            Time.timeScale = 0;
            //show cursor
            Cursor.visible = true;
            itemSpawnerManager.enabled = false;
            simpleShooting.enabled = false;
        }
        else
        {
            character.SetActive(true);
            pauseMenu.SetActive(false);
            Time.timeScale = 1;
            Cursor.visible = false;
            itemSpawnerManager.enabled = true;
            simpleShooting.enabled = true;
        }
    }
}

and this is the script that the other script needs:

using System.Collections;
using UnityEngine;
namespace simpleShootingNS
{


    public class simpleShooting : MonoBehaviour
    {
        public GameObject bullet;
        public GameObject spawnPos;

        void Start()
        {

        }

        void Update()
        {
            if (Input.GetMouseButton(0))
            {
                Instantiate(bullet, spawnPos.transform.position, spawnPos.transform.rotation);

            }
        }
    }
}

First of all, naming conventions, a class should be uppercase
I don’t really know why you’re using a namespace for this class, it seems like a wrapper for the other, but as long as it’s not a pack of scripts, like a bunch of different math classes, then I wouldn’t recommend it

I used namespaces because I what trying to get it the work so it’s is only for testing but nothing works

I agree with the advice from @gorbit99 and I would also strongly recommend against what you’ve done in line 14 – it’s a very bad idea to use a variable name that is exactly the same as the class name. (You didn’t say when/where this error is shown; maybe Unity’s hacked compilers have a problem with this…)

public simpleShooting simpleShooting;

Take gorbit99’s advice and name your class SimpleShooting, which is the normal formatting for class names, and leave your variable name simpleShooting. Maybe you’ll get lucky and that will be the problem. There doesn’t seem to be any syntax problems with the code you posted as far as real C# / .NET goes though.

To expand on gorbit99’s comments:

A namespace is meant to allow you to name groups of related functionality without risk of choosing a name already used elsewhere. For example, .NET’s System assembly exposes the namespace System.Diagnostics where .NET’s Debug class is defined, and Unity’s .NET assembly has the UnityEngine namespace where Unity’s Debug class is defined. Two classes by the same name, but you can use both in the same project (or even the same method) by differentiating them according to their namespace.

What he is saying is that you don’t appear to need a namespace at all. In many simple Unity programs you can leave out namespaces altogether. In a professional setting this is bad practice, you are “polluting” the global namespace, but for learning or small projects it’s fine.

1 Like

Alright i changed my scripts:

main script:

using System.Collections;
using UnityEngine;
// using simpleShootingNS;
// using itemSpawnerManagerNS;
public class PauseManager : MonoBehaviour
{
    [HeaderAttribute("keybind to enable/disnable pause menu")]
    public KeyCode PauseKeyBind;
    [HeaderAttribute("player character to disnable")]
    public GameObject character;
    [HeaderAttribute("GameObject of pauseMenu to en/disnable")]
    public GameObject pauseMenu;
    //[SpaceAttribute("extra scripts that needs to disnable || this will fill in automaticly!")]
    public simpleShooting SimpleShooting;//error
    public itemSpawnerManager ItemSpawnerManager;//error

    bool isPaused;

    void Start()
    {
        SimpleShooting = GameObject.Find("SCRIPTS").GetComponent<simpleShooting>(); // error
        ItemSpawnerManager = GameObject.Find("SCRIPTS").GetComponent<itemSpawnerManager> (); // error
    }

    void Update()
    {
        if (Input.GetKeyDown(PauseKeyBind))
        {
            isPaused = !isPaused;
        }
        if (isPaused)
        {
            //disnable player character
            character.SetActive(false);
            //enable gm of paus menu
            pauseMenu.SetActive(true);
            //time scale
            Time.timeScale = 0;
            //show cursor
            Cursor.visible = true;
            itemSpawnerManager.enabled = false;
            simpleShooting.enabled = false;
        }
        else
        {
            character.SetActive(true);
            pauseMenu.SetActive(false);
            Time.timeScale = 1;
            Cursor.visible = false;
            itemSpawnerManager.enabled = true;
            simpleShooting.enabled = true;
        }
    }
}

other script:

using System.Collections;
using UnityEngine;

public class simpleShooting : MonoBehaviour
{
    public GameObject bullet;
    public GameObject spawnPos;

    void Start()
    {

    }

    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            Instantiate(bullet, spawnPos.transform.position, spawnPos.transform.rotation);

        }
    }
}

errors:

Is it possible that one of these scripts is in a Plugins or Editor folder and the other is not?

1 Like

nope, all in the same scripts folder

Expand all the folders and post a screen shot of your Project window. (You don’t have to use imgur, you can drag the jpg to the forum message window and attach it directly, as I’ve done here.)

2997794--223377--1.jpg

2997881--223386--upload_2017-3-17_22-11-8.pngthats the only scipts i have

The question I have now is… where are these errors being reported? Because it just occurred to me that the screenshot you posted of your errors is not the Unity console.

1 Like

errors has been changed but here they are from unity console:

Alright, now we can get somewhere, now that we’re looking at the actual errors (and not what I presume to be an improperly configured IDE’s errors).

And I’ll bring you back to this from the first reply

Your naming conventions are backwards of every other piece of code you’re going to come across. There’s nothing that’s going to prevent them from compiling, if you can keep them straight in your head. But if you can’t, then that’s how you’ll end up with errors like what you’re seeing here: mixing up the class name and the variable name.

The quick fix is, anytime you have that error, switch it to the uppercase (variable) name.

The “making good coding habits” fix is, rename your classes (including their filenames) to start with uppercase letters, then rename the variables in PauseManager.cs to have lowercase first letters (or “camel case” as it’s known). This will be consistent with just about every Unity code example you’ll ever be modeling your code off of, and will make it much easier to learn those things.

In your update method, you are not using the variable to access the enabled state.
Since you reversed your naming convention, you have to call SimpleShooting.enabled
and not simpleShooting.enabled. As the other two guys recommend, you should change
your class name to pascal casing and your instance variable to camel casing.

i.e: SimpleShooting simpleShooting;

1 Like

thank you guys for the help, the naming whas the problem