Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

The type or namespace name '' could not be found

Discussion in 'Scripting' started by larswik, Aug 2, 2018.

Thread Status:
Not open for further replies.
  1. larswik

    larswik

    Joined:
    Dec 20, 2012
    Posts:
    312
    I do not know what I am missing to make this work? It can not find the NetworkPlayerScript that is located on a prefab? The Awake() below is trying to access the script to get a value of a variable. It is something with the namespaces but I can't resolve the issue.

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6. using UnityEngine.Networking;
    7.  
    8. public class LoadLevelsScript : MonoBehaviour {
    9. void Awake(){
    10.    //network
    11.    if (worldMapScript.isNetworkGame){  
    12.          NetworkPlayerScript script =  GameObject.Find("Network Player(Clone)").GetComponent<NetworkPlayerScript>();
    Here is the header information of the NetworkPlayerScript.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.Networking;
    6.  
    7. namespace Prototype.NetworkLobby
    8. {
    9.  
    10.     public class networkPlayerScript : NetworkBehaviour {
    11.  
    12.         public Camera pCam;
    13.         public string screenText = "It works";
    Any help is appreciated.
     
  2. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    First, are you using Visual Studio (or similar)? If so, it will show a red squiggly underline on
    NetworkPlayerScript script
    . If you hover on that, some suggested fixes will be shown to you.

    However, you can either add a
    using Prototype.NetworkLobby;
    or you can directly reference it inline with
    Prototype.NetworkLobby.NetworkPlayerScript script
    . Note: there is no need to do both.
     
    SkullKnight0 likes this.
  3. Rotary-Heart

    Rotary-Heart

    Joined:
    Dec 18, 2012
    Posts:
    804
    You are using the GetComponent with the wrong script name. Compare what you have on it vs the actual script name.

    GetComponent<NetworkPlayerScript>()

    public class networkPlayerScript
     
    Cbp846, Bunny83 and Doug_B like this.
  4. larswik

    larswik

    Joined:
    Dec 20, 2012
    Posts:
    312
    Thanks guys! both your answers solved my problem. Doug, I did try that earlier and it wasn't working but as Rotery-Heart pointed out the upper case 'N'. once I fixed that, your solution worked!

    Thank you both!
     
    Doug_B likes this.
  5. MushiUnity

    MushiUnity

    Joined:
    Oct 20, 2018
    Posts:
    7
    upload_2018-10-28_4-10-29.png

    upload_2018-10-28_4-10-58.png

    can anyone help me for this error please
     
    Rizwan0123456 likes this.
  6. davepalasol06

    davepalasol06

    Joined:
    Jan 12, 2020
    Posts:
    3
  7. davepalasol06

    davepalasol06

    Joined:
    Jan 12, 2020
    Posts:
    3
    please help how to fix this?
     
  8. Kofiro

    Kofiro

    Joined:
    Feb 3, 2017
    Posts:
    29
    Check

    Code (CSharp):
    1. public controller SP;
    You probably put a lowercase C instead of

    Code (CSharp):
    1. public Controller SP;
     
Thread Status:
Not open for further replies.