So, I have a basic Raycast targetting system set up…
if (Input.GetButton("Fire1"))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast (ray, out hit, 250))
{
if (hit.transform.tag != "terrain")
{
target = hit.transform;
Debug.Log ("Target Tag = " +hit.transform.tag);
}
} else {
target = null;
}
}
but, I need to find a way to incorperate it with the following code, so I can get the stats of my target. I was told that there is a way to pull the selected npc from the dictionary, please note that I am not using MonoBehavior scripts so it’s not as easy as drag/drop. I would think that I’d have to set up some sort of Identification system, such as “public in NPCID” and try to figure out how to incorperate that, although I’m not sure…
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class NPCs {
public static NPCs instance;
public static NPCs GetInstance()
{
if (instance == null)
{
instance = new NPCs();
}
return instance;
}
public Dictionary<GameObject, NPC> npcList = new Dictionary<GameObject, NPC>();
public void createNPC(string name, int maxHealth, int expReward, int maxDamage, Vector3 position) {
// Instantiate game object here
GameObject npcGameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
NPC npc = new NPC();
npcList.Add(npcGameObject, npc);
npcGameObject.transform.position = position;
npcGameObject.tag = "Mob";
npcList[npcGameObject].npcName = name;
npcList[npcGameObject].maxHealth = maxHealth;
npcList[npcGameObject].currentHealth = npcList[npcGameObject].maxHealth;
npcList[npcGameObject].expReward = expReward;
npcList[npcGameObject].npcDamage = maxDamage;
}
public class NPC {
public string npcName {get; set;}
public int currentHealth {get; set;}
public int maxHealth {get; set;}
public int expReward {get; set;}
public int npcDamage {get; set;}
}
}