The Type or namespace name could not be found

Hello,

I am new to coding and mostly use Playmaker, but I have two asset store assets I want to get working together so I’m trying to edit the damage component of one to apply to the other. I keep getting the namespace error even if I add it to the ‘using’ field at the start which is what every answer on google suggests. Anyone able to help me out? Code for the two scripts are below, both located in the assets folder but under different sub folders.

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

namespace DestroyIt
{
    /// <summary>Put this script on an object you want to be destructible.</summary>
    [DisallowMultipleComponent]
    public class Destructible : MonoBehaviour

^ This is the code for the object I want to damage

if (Physics.Raycast(BulletOrigin.position, direction, out var hit, BulletRange, HitMask, QueryTriggerInteraction.Ignore))
            {
                OnHit(hit, BulletOrigin.forward);
                hitLocation = hit.point;
                Destructible destructible = hit.transform.GetComponent<Destructible>();
                if (destructible != null)
                {
                    destructible.ApplyDamage(GunDamage);
                }

^ This is the code that is giving me the namespace error, even if I put using DestroyIt or using Destructible at the start. Edit: Error is on line 5, Unity says that the namespace ‘Destructible’ could not be found.

If you need to see more code to help, let me know, I tried to put only the necessary bits as they are paid assets.

Thanks in advance.

Adding using DestroyIt; at the top of your script should be all you need to do.
Make sure you save all your scripts and ensure that there aren’t any other compiler errors afterwards.

I tried that and unfortunately it didn’t work. After some more digging, it appears that the code that is giving me the error is inside an assembly definition. I apparently need to add a reference to another class before I can use it. Do you know how I can do this within unity?

Found it, I had to create an assembly definition in unity (right click > create) on the script folder which contained the DestroyIt code. Then in the inspector I assigned this as a reference to the original script and it appears to be working now.

1 Like