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 Can't Solve Error cs0246

Discussion in 'Editor & General Support' started by Eyebullistik, Aug 26, 2023.

  1. Eyebullistik

    Eyebullistik

    Joined:
    Oct 24, 2021
    Posts:
    3
    I am working on a survival game and I am following a tutorial and I am getting error code CS0246

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class SelectioinManager : MonoBehaviour
    6. {
    7.     public GameObject Interaction_Info_UI;
    8.     Text Interaction_text;
    9.     private void Start()
    10.     {
    11.         Interaction_text = Interaction_Info_UI.GetComponent<Text>();
    12.     }
    13.     void Update()
    14.     {
    15.         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    16.         RaycastHit hit;
    17.         if (Physics.Raycast(ray, out hit))
    18.         {
    19.             var selectionTransform = hit.transform;
    20.             if (selectionTransform.GetComponent<InteractableObject>())
    21.             {
    22.                 Interaction_text.text = selectionTransform.GetComponent<InteractableObject>().GetItemName();
    23.                 Interaction_Info_UI.SetActive(true);
    24.             }
    25.             else
    26.             {
    27.                 Interaction_Info_UI.SetActive(false);
    28.             }
    29.         }
    30.     }
    31. }
    32.  
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,362
    Share the full error. We aren't walking collections of thousands error codes
     
    bugfinders likes this.
  3. Eyebullistik

    Eyebullistik

    Joined:
    Oct 24, 2021
    Posts:
    3
    SelectionManager.cs(25,49): error CS0246: The type or namespace name 'InteractableObject' could not be found (are you missing a using directive of an assembly reference?)

    SelectionManager.cs(27,73): error CS0246: The type or namespace name 'InteractableObject' could not be found (are you missing a using directive of an assembly reference?)
     
  4. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    1,834
    Seems pretty self-explanatory. Your tutorial should be providing this script as well, which you should be keeping in InteractableObject.cs asset file.
     
  5. Eyebullistik

    Eyebullistik

    Joined:
    Oct 24, 2021
    Posts:
    3
    Thank you i got it fixed
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    For future reference, you can solve all your own typing mistakes yourself. 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.