List of Class With GameObject
Hello, Unity Community.
I'm trying to make a dynamic table as shown on Fig.1.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
//List Of Class NPC(GameObject, x, y, z, p, Hi, Hc)
public class NPC : MonoBehaviour {
public GUIStyle customGuiStyle;
public RandomPressure _RandomPressure;
public Label1 _Label1;
private GameObject GONPC;
private int i;
private int s1;
private string s;
private float xnpc;
private float ynpc;
private float znpc;
private float pplayer;
private float Hinitial;
private float Hcurrent;
private List<NPC> NPCList = new List<NPC>();
public NPC(GameObject GONPC1, float xnpc1, float ynpc1, float znpc1, float pplayer1, float Hinitial1, float Hcurrent1)
{
GONPC1 = GameObject.FindGameObjectWithTag("NPC");
GONPC = GONPC1;
xnpc = xnpc1;
ynpc = ynpc1;
znpc = znpc1;
pplayer = pplayer1;
Hinitial = Hinitial1;
Hcurrent = Hcurrent1;
}
void Start()
{
Hinitial = 100;
}
void Update()
{
NPCList = new List<NPC>();
for (i = 0; i == NPCList.Count; i++)
{
GONPC = GameObject.FindGameObjectWithTag("NPC");
xnpc = GONPC.transform.position.x;
ynpc = GONPC.transform.position.y;
znpc = GONPC.transform.position.z;
pplayer = _RandomPressure.p;
Hcurrent = _Label1.F * (-1) + Hinitial;
}
}
void OnGUI()
{
s1 = NPCList.Count;
s = s1.ToString();
GUI.Label(new Rect(10, 10, 200, 20), s, customGuiStyle);
}
}
In game I always see s=0. There must be something wrong with my code. How can I make a dynamic list of class NPC?
table-1and2.gif
(6.7 kB)
Comment