Im trying to create a player display using OnGUI that is a base object, while accepting user input from a seperate user interface in another class. I want to take that input and create that many player displays. Im going to create another class that holds both interfaces, so it will first pop up and ask how many players. then based on that number it will create that many user displays, each one having an (offset * n) so that they are spaced out appropriately. im not sure if im even going about this the right way so here is my code. i tried using an array with a foreach to initialize each display. Any and all help will be appreciated.
here is my playerdisplay script
using UnityEngine;
using System.Collections;
using System;
public class PlayerDisplay : MonoBehavior {
private int life;
private bool isalive = true;
private int minlife = 0;
private const int OFFSET = 50;
private int n;
private const int XAXIS = x;
}
void Start() {
}
void Update() {
}
public void OnGUI(){
DisplayPlayerDisplay();
DisplayLifeStats();
}
public void DisplayPlayerDisplay() {
GUI.Box(new Rect(XAXIS + (OFFSET * n),y,x,y), “Player”);
}
public void DisplayLifeStats() {
GUI.label(new Rect(XAXIS + (OFFSET * n),y,x,y),”life”, life.ToString());
If(GUI.Button(new Rect(x,y,x,y), “+“)
life++;
If(GUI.Button(new Rect(x,y,x,y), “-”) {
life--;
if(life <= minlife;){
life = minlife;
}
return life;
}
}
and here is my player counter script
using UnityEngine;
using System.Collections;
using System;
public class PlayerCounter : MonoDevelopment {
private int pa = 2;
private int minpa = 2;
}
void Start() {
}
void Update() {
}
public void OnGUI() {
DisplayPlayerCounter();
}
public void DisplayPlayerCounter() {
GUILayout.BeginArea(new Rect(x,x,x,x));
If(GUILayout.Button(“-”)) {
pa--;
}
If(pa <= minpa)
pa = minpa;
If(GUILayout.Button(“+”)) {
pa++;
if(GUILayout.Button(“Done”)) {
return pa;
}
GUILayout.EndArea();
and my player script that ties them all together
using UnityEngine;
using System.Collections;
using System;
public class Player : MonoBehaviour {
public int life = 20;
PlayerCounter pc = new PlayerCounter();
PlayerDisplay pd = new PlayerDisplay();
public Int n;
}
void Start() {
int n = pc.DisplayPlayerCounter();
}
void Update() {
Public void PlayerCreation() {
Players player[] = new Players(n);
Foreach(int newplayers in player)
{
Pd.DisplayPlayerDisplay();
Pd.DisplayLifeStats();
}
}