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

Question Error cs0246

Discussion in 'Scripting' started by unity_jjhtpWoQZZx2Hw, Dec 20, 2020.

  1. unity_jjhtpWoQZZx2Hw

    unity_jjhtpWoQZZx2Hw

    Joined:
    Oct 30, 2020
    Posts:
    9
    Hi folks,

    I've the error cs0246 in one of my scripts, so my game doesn't work. In the script Inventory.cs is the script error. Here's the code of the script:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Inventory : MonoBehaviour {
    6.    
    7.     public ItemDatabase database;
    8.    
    9.     int slotAmount = 9;
    10.     int storageAmount = 36;
    11.    
    12.     public GameObject slot;
    13.     public GameObject hotbarPanel;
    14.     public GameObject inventoryPanel;
    15.    
    16.     // Start is called before the first frame update
    17.     void Start() {
    18.         database = gameObject.GetComponent<ItemDatabase>();
    19.     }
    20.  
    21.     // Update is called once per frame
    22.     void Update() {
    23.        
    24.     }
    25. }
    26.  
    and I also have an image of the script error:

    Bildschirmfoto 2020-12-20 um 08.31.52.png
    I need VERY URGENTLY help, so it may be really nice for me, if you can help me!

    Sincerely yours,
    Atten007
     
  2. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    The error message already tells you what is wrong: you need to import the class, library or namespace that defines ItemDatabase.

    'Importing' is done with the 'using xxxxx' statements at the top of your code.
     
  3. unity_jjhtpWoQZZx2Hw

    unity_jjhtpWoQZZx2Hw

    Joined:
    Oct 30, 2020
    Posts:
    9
    Hi csofranz,

    The error is already fixed in my game, but thank you for your help!

    Sincerely yours,
    Atten007