I am attempting to create a character generator script.
I’m making private variables to grab the names from the enum list. That is working, but when I try to define a public variable with a random int and place it in the OnGUI, it doesn’t like it whether I put the definitions in awake or start.
Here is the code:
using UnityEngine;
using System.Collections;
using System;
public class CharacterGenerator : MonoBehaviour
{
public const float VERSION=.1f;
public bool ClearPrefs=false;
private string _constitution= Attributes.Stat.Constitution.ToString();
private string _strength= Attributes.Stat.Strength.ToString();
private string _stamina= Attributes.Stat.Stamina.ToString();
private string _dexterity= Attributes.Stat.Dexterity.ToString();
private string _intelligence= Attributes.Stat.Intelligence.ToString();
private string _wisdom= Attributes.Stat.Wisdom.ToString();
private string _focus= Attributes.Stat.Focus.ToString();
// Use this for initialization
void Start ()
{
public Constitution=Random.Range(1, 20); //error here with red line
//public int Strength= UnityEngine.Random.Range(1, 20);
//public int Stamina= UnityEngine.Random.Range(1, 20);
//public int Dexterity= UnityEngine.Random.Range(1, 20);
//public int Intelligence= UnityEngine.Random.Range(1, 20);
//public int Wisdom= UnityEngine.Random.Range(1, 20);
//public int Focus= UnityEngine.Random.Range(1, 20);
}
// Update is called once per frame
void Update ()
{
public Constitution=Random.Range(1, 20); here too
}
void GenerateStats()
{
GUI.Label (new Rect (40, 50, 700, 50), _constitution + ":" + Constitution );
GUI.Label (new Rect (40, 70, 700, 50), _strength + ":" + Strength);
GUI.Label (new Rect (40, 90, 700, 50), _stamina + ":" + Stamina);
GUI.Label (new Rect (40, 110, 700, 50), _dexterity + ":" + Dexterity);
GUI.Label (new Rect (40, 130, 700, 50), _intelligence + ":" + Intelligence);
GUI.Label (new Rect (40, 150, 700, 50), _wisdom + ":" + Wisdom);
GUI.Label (new Rect (40, 170, 700, 50), _focus + ":" + Focus);
}
void OnGUI()
{
GUI.Label (new Rect (Screen.width/2, 10, 700, 50), "True Calling Character Generator!");
if(GUI.Button (new Rect (250, 300, 100, 50), "Generate Stats")){
Debug.Log("Generate our Stats!");
GenerateStats();
}
if (GUI.Button (new Rect (355, 300, 100, 50), "Start Game")){
Debug.Log("Start Our Game!");
}
}
}
Only the OnGUI stuff is showing up. It worked once when everything was in the OnGUI function, but when I tried it again, I got an exception and zero values.
What am I doing, not doing, should be doing?
Thanks!