Hello all , i am using C# to create a game , i want to create my Class Of NPC which has it’s name and info and a GameObject att. to link it to the GameObject inside the game , what i want to know is how can i get the NPC info using the GameObject in the game ? Thank you .
Do you mean getting info from a script attached to a GameObject? If so, something along those lines:
//let's say you want to access info about the object "possibleNpc"
if(possibleNpc.tag=="NPC")
{
var infoScript = possibleNpc.GetComponent<YourInfoScriptType>();
if(infoScript != null)
{
//access info script here.
}
}
Where possibleNpc is a GameObject and YourInfoScriptType is a MonoBehaviour that contains your info about the NPC.
Also, tag your NPC GameObject as “NPC”.