why I get : the type or namespace name 'SpawnManager' could not be found(are you missing a using dir

Open the SpawnManager.cs file to check what namespace is SpawnManager declared inside:

namespace SomeNamespace
{
    public class SpawnManager
    {
        ...
    }
}

Then add this namespace at the top of Player.cs:

using SomeNamespace;
1 Like

May or not be related, but something is up with your Unity/Visual Studio integration. The fact that it says “Miscellaneous C# files” in the top left means VS doesn’t know what assembly your code belongs to. By default this should say something like “Assembly-CSharp”.

Hi Guys i have a simmilar problem i belive i does same course that as person who created that post.
I will post error i get and screens from code below.
"
Assets\Scenes\Scripts\Player.cs(20,13): error CS0246: The type or namespace name ‘SpawnManager’ could not be found (are you missing a using directive or an assembly reference?)
"

You have the same exact problem I mentioned above:
https://discussions.unity.com/t/803130/3

You need to configure Visual Studio, as per these instructions:
https://learn.microsoft.com/en-us/visualstudio/gamedev/unity/get-started/getting-started-with-visual-studio-tools-for-unity?pivots=windows#install-unity-support-for-visual-studio

As for your actual code problem - Spawn_Manager is not the same as SpawnManager.

1 Like

Yes, I agree: you are also just making silly typing mistakes.

Stop doing that because the computer is going to FORCE you to fix them all before you can do anything.

So why not type it correctly to start with?

When you make a typing mistake, you do not need the forum. You need to fix your typing. Here’s how:

Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

The complete error message contains everything you need to know to fix the error yourself.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly?

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

How to do tutorials properly, two (2) simple steps to success:

Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That’s how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.
Fortunately this is the easiest part to get right: Be a robot. Don’t make any mistakes.
BE PERFECT IN EVERYTHING YOU DO HERE!!

If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there’s an error, you will NEVER be the first guy to find it.

Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!

Finally, when you have errors, don’t post here… just go fix your errors! Here’s how:

1 Like

Hi thank you very much for quick answer i really appreciate it.
I did fixed VS studio-Unity link and it does saids “Assembly-CSharp”. Thank you very much for that.

I cant get around second issue. I tried to change the name but it pop out another Error. I Quote error below.

“Assets\Scenes\Scripts\Player.cs(4,7): error CS0138: A ‘using namespace’ directive can only be applied to namespaces; ‘Spawn_Manager’ is a type not a namespace. Consider a ‘using static’ directive instead”

Would be very greatfull if you could point out which line of code i should to replace the “SpawnManager”
I will try to explain what the code should to do and what i acctualy did in unity.

Inside Spawn_Manager script there is a variable “_stopSpawning” that has a booliant value set to it.
It used in While Loop that was created in intention of constant enemy spawning till player is dead which is variable created on line 50 of “public void OnPlayerDeath()”

Inside Player script (We want our player to communicate with Spawn_manager so if player dies enemies stop spawning - find the object and get component)
I got variable "private Spawn_Manager _spawnManager;" on line 21 - But i dont get it why is it this way (I fallow unity course and structure everything just like in the acctual course.

I got variable that look in to game object named “Spawn_Manager” and trying to get component. in course it saids <component> should always match with orignal code from line 21 - “SpawnManager”
_spawnManager = GameObject.Find(“Spawn_Manager”).GetComponent<SpawnManager>();

Im sorry that my explenation is not clear but i just began doing this unity course and these are my first steps with CSHARP and Unity and tbh there are points where i just get lost.

IN UNITY :
I got “Player” game object which is linked to “Player” script.
I got as well “Spawn_Manager” game object that its linked to “Spawn_Manager” script.
“Spawn Manager” game object contains “Enemy_Container” game object.

IN Virtual Studio :

Player SCRIPT :

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

public class Player : MonoBehaviour
{
    //if varieble is public other game objects can manipulate it like power ups. if its private other objects or scripts cant manipulate is value.
    //[Serial Field] alows us to manipulate value from unity inspector even if its private.
    [SerializeField]
    private float _speed = 6.3f;
    [SerializeField]
    private GameObject _laserPrefab;
    [SerializeField]
    private float _fireRate = 0.2f;
    [SerializeField]
    private float _canFire = -1f;
    [SerializeField]
    private int _lifes = 3;

    private Spawn_Manager _spawnManager;




    public float horizontalInput;
    public float verticalInput;

    // Start is called before the first frame update
    void Start()
    {
        // take the curent position = new position (0,0,0)
       
       
        transform.position = new Vector3(0, 0, -3);

        _spawnManager = GameObject.Find("Spawn_Manager").GetComponent<SpawnManager>();

        if (_spawnManager == null)
        {
            Debug.LogError("The Spawn Manager is NULL.") ;

        }

    }

    // Update is called once per frame
    void Update()
     
    {
        CalculateMovement();

        if (Input.GetKeyDown(KeyCode.Space) && Time.time > _canFire)
        {
            FireLaser();
        }

    }
    void CalculateMovement()
    {
        float horizontalInput = Input.GetAxis("Horizontal");
        float verticalInput = Input.GetAxis("Vertical");

        float tiltSideAngle = -35.5f;
        float tiltFrontAngle = 15.9f;
        float smooth = 7.9f;

        //Expelanation of what happen below Vector 3 (1,0,0) * 0  *  * real time
        //transform.Translate(Vector3.right * horizontalInput * _speed * Time.deltaTime);
        //transform.Translate(Vector3.up * verticalInput * _speed * Time.deltaTime);

        // More optimised version of code above.
        // transform.Translate(new Vector3(horizontalInput, verticalInput, 0) * _speed * Time.deltaTime);


        // Even more optimised version of code above.

        Vector3 direction = new Vector3(horizontalInput, 0, verticalInput);

        transform.Translate(direction * _speed * Time.deltaTime);
     

        float tiltAroundZ = Input.GetAxis("Horizontal") * tiltSideAngle;
        float tiltAroundX = Input.GetAxis("Vertical") * tiltFrontAngle;

        Quaternion target = Quaternion.Euler(tiltAroundX, 0, tiltAroundZ);
        transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);


        // if plaer position on the y is greater then 0
        // y position = 0
        // else if position on the y is > then -0.89f
        // y pos =-0.89f

        if (transform.position.z >= 14.4f)
        {
            transform.position = new Vector3(transform.position.x, 0, 14.4f);
        }
        else if (transform.position.z <= -10.6f)
        {
            transform.position = new Vector3(transform.position.x, 0, -10.6f);
        }

        if (transform.position.x >= 22.85f)
        {
            transform.position = new Vector3(22.85f, 0, transform.position.z);
        }
        else if (transform.position.x <= -22.85f)
        {
            transform.position = new Vector3(-22.85f, 0, transform.position.z);
        }
        if (transform.position.y >= 0.0f)
        {
            transform.position = new Vector3(transform.position.x , 0 , transform.position.z);
        }
        else if (transform.position.y <=0)
            transform.position = new Vector3(transform.position.x, 0, transform.position.z);
        if (tiltAroundX <= -3)
        {
            tiltAroundX = -3;
        }
        // if player on the x is > 11
        // x position = - 11
        //else if player on the x < -11
        // x position = -11
    }
    void FireLaser()
    {
        //if i press space key
        // spawn game object   
        {
            _canFire = Time.time + _fireRate;
            Instantiate(_laserPrefab, transform.position + new Vector3(0,0,1), Quaternion.identity);
        }
    }


    public void Damage()
    {
        //_lifes = _lifes -1
        //_lifes -= 1;
        //_lifes --
        _lifes--;
        //check if daad
        //destroy us
        if (_lifes < 1)
        {
            _spawnManager.OnPlayerDeath();

            // Comunicate with spawn manger
            // let it know to stop spawning enemies.


            Destroy(this.gameObject);



        }

    }


}

SPAWN_MANAGER SCRIPT :
```csharp
**using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Spawn_Manager : MonoBehaviour
{

[SerializeField]
private GameObject _enemyPrefab;
[SerializeField]
private GameObject _Enemy_Container;

private bool _stopSpawning = false;

// Start is called before the first frame update
void Start()
{
    StartCoroutine(SpawnRoutine());
   
}

// Update is called once per frame
void Update()
{
   

  
}

// spawn game object every 5 second
//create courtine of type IEmulator -- Yield Events

IEnumerator SpawnRoutine()
{
    while (_stopSpawning == false)
    {

        Vector3 posToSpawn = new Vector3(Random.Range(-23.5f, 23.5f), 0, 19.5f);
        GameObject newEnemy = Instantiate(_enemyPrefab, posToSpawn, Quaternion.identity);
        newEnemy.transform.parent = _Enemy_Container.transform;
        yield return new WaitForSeconds(7.0f); // wait 7  seconds
   
    }

    //while loop (infinite loop)
    //instantiate enemy prefab
    // yield wait for 5 seconds
}
public void OnPlayerDeath()
{
    _stopSpawning = true;


}

}**
```
Regards.

There is no need for using Spawn_Manager; and all it’s doing is causing an error. Simply delete that line.

As for GetComponent<SpawnManager>(); again the name has to match everywhere. Since your class is called Spawn_Manager, you would have to write GetComponent<Spawn_Manager>();

However I would recommend always following C# naming conventions and renaming it to SpawnManager everywhere instead.

1 Like

Hi thank you very much for quick answer and lots of useful advices its looks like you have a lot of experience.
This is my first unity course, first unity project ever, and first c sharp script ever.
I came across this problem and what i DID - IS ACCTUALY EXACT THING THAT YOU ADVICED ME TO DO.
I WENT GOOGLE AND GOOGLE IT.
AND IT ACCTUALY TOOK ME HERE.
BECAUSE JUST LIKE YOU SAID - SOMEONE ELSE ALREADY HAD THIS PROBLEM.
THIS IS WHY IM POSTING HERE I HAD IMPRESION THAT THIS IS EXACLY WHAT I SHOULD TO DO CHECK IF SOMEONE ELSE HAD THIS PROBLEM AND SEE DID THEY FIXED IT OR NOT IF NOT THEN ASK.
IM A BIT CONFUSED AS YOU GIVING ME ADVICES AND AT SAME TIME SEEMS TO BE NOT HAPPY ABOUT ME FULLFILING SOME OF THOSE ADVICES.

I tried to explained it to plant but as this is my VERY FIRST C SHARP PROJECT EVERY i just dont get it yet.

Thank you for all of the pro advices.
Be blessed

Thank you very much.

Thank you very much i think i will have to put some time to C sharp it self before i countinue with that course.

From video i know that component name has to match but i dont undestand that part “Since your class is called Spawn_Manager, you would have to write ```GetComponent<Spawn_Manager>”

Why component inside “<>” should have same name as class if code should to get.component not class.
Is component and class the same thing ??? Im sorry but i just got lost.
I think i will do some c sharp basic videos and then back to that course as its my first c sharp experience and there wasnt really much explained about it so i just my go study it first.

Regards.```

PLEASE stop necro-posting to someone else’s 2020 thread.

Go start your own thread. It’s FREE!

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

Unity’s component architecture

https://forum.unity.com/threads/custom-gameobject.967582/#post-6299125

Terminology primer for assets:

https://forum.unity.com/threads/convert-sliced-sprites-into-materials-for-quads.1369056/#post-8632563

Try this approach: ask yourself again and again… “Can I?”

Imphenzia: How Did I Learn To Make Games:

1 Like

Hi

Hi thank you very much.
Be blessed for the links and all of the advices !!
I will check the links now, maybe expect that first link you post as for some reason its not HTTPS but HTTP and that mean that its not SECURED and its its just to weird that any legit website in 2023 wouldnt be HTTPS as its the most basic thing that you could do to secure connection. So i may just stay away from this one as i doesnt look legit, but definitely will check rest of them.

Once again thank you for the advices be blessed !!!

You wrote:

public class Spawn_Manager : MonoBehaviour

Therefore the name of your class is Spawn_Manager. That’s all.

1 Like

The most blessed advice by far is to stop necro-posting to someone else’s thread from 2020.

The second-most-blessed advise is to start your own thread, it’s FREE.

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

1 Like