Npc Editor Script

Anyone Help fix these errors.

  • Remove the parentheses on Selection.activeGameObject().
  • Don’t know what NPCObject is, but it does not appear to inherit from MonoBehaviour, so you cannot add it as a component onto a GameObject.
  • You’re trying to access a member called NPCType that doesn’t exist inside of NPCObject.

Thanks how do i fix the other errors?

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using UnityEditor;
using UnityEngine.UIElements;

public class CreateNPCEditorWindow : EditorWindow
{
    GameObject go = null;

    string NPCName;
    string NPCLevel;
    string NPCExpMin;
    string NPCExpMax;
    string NPCStartHealth;
    string NPCHealth;
    string NPCAttackMin;
    string NPCAttackMax;
    string NPCStopDistance;
    string NPCAct;
    NPC.NPCType NPCType;

    [MenuItem("Window/Create a New NPC")]
    public static void ShowWindow()
    {
        GetWindow<CreateNPCEditorWindow>("Create New Npc");
    }

    void OnGUI()
    {
        Repaint();

        if (Selection.activeGameObject == null)
        {
            GUILayout.BeginHorizontal("Box");
            GUILayout.Label("Select a 3d Model or GameObject.", EditorStyles.centeredGreyMiniLabel);    // Title
            GUILayout.EndHorizontal();
            return;
        }

        GUI.color = Color.cyan;

        GUILayout.BeginHorizontal("Box");
        GUILayout.FlexibleSpace();
        GUILayout.Label("Create a New Npc", EditorStyles.whiteBoldLabel);   // Title
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        GUI.color = Color.green;

        GUILayout.BeginHorizontal("Box");
        NPCType = (NPC.NPCType)EditorGUILayout.EnumPopup("Race", NPCType);

        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        GUI.color = Color.white;

        GUILayout.BeginHorizontal("Box");
        NPCName = EditorGUILayout.TextField("Name", NPCName);   // Choose Enemy Name
        go = Selection.activeGameObject;
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal("Box");
        NPCLevel = EditorGUILayout.TextField("Level", NPCLevel);   // Choose Enemy Level
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal("Box");
        NPCExpMin = EditorGUILayout.TextField("Exp Minimum", NPCExpMin);   // Choose Enemy Minimum Exp Gain
        NPCExpMax = EditorGUILayout.TextField("Exp Maximum", NPCExpMax);   // Choose Enemy Maximum Exp Gain
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal("Box");
        NPCStartHealth = EditorGUILayout.TextField("Starting Health", NPCStartHealth); // Choose Enemy Starting Health
        NPCHealth = EditorGUILayout.TextField("Health", NPCHealth);    // Choose Enemy Health
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal("Box");
        NPCAttackMin = EditorGUILayout.TextField("Attack Damage Minimum", NPCAttackMin);   // Choose Enemy Attack Damage 5 Refers to 5 Hp
        NPCAttackMax = EditorGUILayout.TextField("Exp Maximum", NPCAttackMax); // Choose Enemy Attack Damage 5 Refers to 5 Hp
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal("Box");
        NPCStopDistance = EditorGUILayout.TextField("Distance To Stop", NPCStopDistance);  // Distance to player for NavMeshAgent to Halt
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal("Box");
        NPCAct = EditorGUILayout.TextField("Act Number", NPCAct);  // Monster is an Act 01 monster (Diablo style of Acts)
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        if (GUILayout.Button("Confirm Creation"))
        {
            go.AddComponent<Animator>();

            NavMeshAgent agent = go.AddComponent<NavMeshAgent>();
            agent.speed = 1;
            agent.angularSpeed = 999;
            agent.acceleration = 999;
            agent.stoppingDistance = int.Parse(NPCStopDistance);

            CapsuleCollider col = go.AddComponent<CapsuleCollider>();
            col.isTrigger = true;

            NPCObject NPC = go.AddComponent<NPCObject>();

            NPC newNPC = ScriptableObject.CreateInstance<NPC>();
            AssetDatabase.CreateAsset(newNPC, "Assets/Objects/" + NPCName + ".assets");
            AssetDatabase.SaveAssets();
            EditorUtility.FocusProjectWindow();
            NPC.NPCType = newNPC;

            Selection.activeObject = NPC;
            Selection.activeObject.name = NPCName;

            CreateObject(newNPC);

        }

    }

    public void CreateObject(NPC newNPC)
    {
        newNPC.NPC_Name = NPCName;
        newNPC.NPC_Types = NPCType;
        newNPC.NPC_Level = int.Parse(NPCLevel);
        newNPC.NPC_EXPMin = int.Parse(NPCExpMin);
        newNPC.NPC_ExpMax = int.Parse(NPCExpMax);
        newNPC.NPC_StartHealth = int.Parse(NPCStartHealth);
        newNPC.NPCHealth = int.Parse(NPCHealth);
        newNPC.NPCAttackMin = int.Parse(NPCAttackMin);
        newNPC.NPCAttackMin = int.Parse(NPCAttackMax);
        newNPC.NPC_StopDistance = int.Parse(NPCStopDistance);
        newNPC.Npc_ActID = int.Parse(NPCAct);

        string localPath = null;
        string TypeOfNPC = newNPC.NPC_Type.ToString();

        if (TypeOfNPC == "Human")
            localPath = "Assets/Prefabs/AI/Humans/" + NPCName + ".prefab";
        else if (TypeOfNPC == "monster")
            localPath = "Assets/Prefabs/AI/Monsters/" + NPCName + ".prefabs";
        else if (TypeOfNPC == "Alien")
            localPath = "Assets/Prefabs/AI/Aliens/" + NPCName + ".prefabs";
        else if (TypeOfNPC == "Demon")
            localPath = "Assets/Prefabs/AI/Demons/" + NPCName + ".prefabs";

        AssetDatabase.GenerateUniqueAssetPath(localPath);
        PrefabUtility.SaveAsPrefabAssetAndConnect(go, localPath, InteractionMode.UserAction);
    }
}
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(fileName = "NPC", menuName = "NPC/New NPC")]
public class NPC : ScriptableObject
{
    [Header("NPC Icon")]
    public Sprite NPC_Profile;

    [Header("NPC Info")]
    public NPCType NPC_Types;
    public enum NPCType { Human = 1, Monster, Alien, Demon }
    public string NPC_Name;

    public int NPC_Level;
    public int NPC_EXPMin, NPC_ExpMax;
    public int NPC_StartHealth, NPCHealth;
    public int NPC_AttackDmgMin, NPC_AttackDmgMax;
    public int NPC_StopDistance;
    public int Npc_ActID;

    [Header("NPC Stats")]
    public Hostiletype NPC_Fear;
    internal object NPC_Type;
    internal int NPCAttackMin;

    public enum Hostiletype { Coward = 1, Average, Normal, Brave, Fearless }

    public void Test()
    {
        Debug.Log("Test");
    }
}

What other errors remain?

those 3

1: NPCObject is not a component, and as such you cannot attach it to a gameobject. You will need to re-think what you are trying to do here - there is no simple answer.

2: NPCObject doesn’t have anything called “NPCType” in it. If you get rid of this line (line 116), then the error will go away, but the script probably won’t function how you want it to.

3: NPCObject is not something that you can select (I actually have no idea what NPCObject is). This is another error that can be solved by removing the line (line 118), but again, will probably not function how you want it to.

I go the script from this video