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. Dismiss Notice

error CS0246: The type or namespace name `BuildingPlacement' could not be found. Are you missing a u

Discussion in 'Scripting' started by smovie9, Sep 11, 2014.

  1. smovie9

    smovie9

    Joined:
    Sep 8, 2014
    Posts:
    5
    Ok, I can't ask this question on answers so I do it here.
    I got this error:
    error CS0246: The type or namespace name `BuildingPlacement' could not be found. Are you missing a using directive or an assembly reference?
    And I don't know how the f* I should solve this! Please help me thnx.
    code:
    using System;
    using UnityEngine;
    using System.Collections;

    public class BuildingManager : MonoBehaviour {
    public GameObject[] buildings;
    private BuildingPlacement buildingPlacement;

    // Use this for initialization
    void Start () {
    buildingPlacement = GetComponent<BuildingPlacement>();
    }

    // Update is called once per frame
    void Update () {
    }
    void OnGUI () {
    for (int i = 0; i <buildings.Length; i ++) {
    if(GUI.Button(new Rect(Screen.width/20,Screen.height/15 + Screen.height/12 * i, buildings.name))) {
    buildingPlacement.SetItem(buildings);
    }
    }
    }
    }
     
  2. BmxGrilled

    BmxGrilled

    Joined:
    Jan 27, 2014
    Posts:
    238
    That error is saying that Unity can't find a class/script named BuildingPlacement.
     
  3. smovie9

    smovie9

    Joined:
    Sep 8, 2014
    Posts:
    5
    But there I have a script called BuildingPlacement!
     
  4. cdevl

    cdevl

    Joined:
    Apr 10, 2013
    Posts:
    180
    Is BuildingPlacement in the same namespace as BuldingManager?
     
  5. smovie9

    smovie9

    Joined:
    Sep 8, 2014
    Posts:
    5
    nope
     
  6. BmxGrilled

    BmxGrilled

    Joined:
    Jan 27, 2014
    Posts:
    238
    then at the top of that script you need to add the namespace, you do that by the using keyword, e.g.
    using System;
    includes the System namespace
     
  7. smovie9

    smovie9

    Joined:
    Sep 8, 2014
    Posts:
    5
    ?
    What do I need to Add?
     
  8. smovie9

    smovie9

    Joined:
    Sep 8, 2014
    Posts:
    5
    I'm new to unity so..
     
  9. BmxGrilled

    BmxGrilled

    Joined:
    Jan 27, 2014
    Posts:
    238
    if BuildingPlacement is in a different namespace, you need to add using NameSpaceHere; to the top of the script.