- Home /
GUISkin breakages
ok this script was working before i started adding on a GUISkin. now it doesn't work even after i removed all the changes...WTF is going on??? i know the placement problem im going to get around to it. if you have any suggestions go ahead. but i really just cannot figure out what i did to break it...oh and on top of that my monodevelop has stopped giving me the quick option for GUI.Label don't know if that is related.
using UnityEngine;
using System.Collections;
using System;
public class CharacterGenerator : MonoBehaviour
{
private PlayerCharacter _hero;
//Stat information
private const int STARTING_POINTS = 400;
private const int MIN_STARTING_ATTRIBUTE_VALUE = 10;
private const int STARTING_VALUE = 50;
private int PointsLeft;
// Use this for initialization
void Start ()
{
_hero = new PlayerCharacter ();
_hero.Awake ();
PointsLeft = STARTING_POINTS;
for (int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++)
{
_hero.GetPrimaryAttribute(cnt).BaseValue = STARTING_VALUE;
PointsLeft -= (STARTING_VALUE - MIN_STARTING_ATTRIBUTE_VALUE);
}
_hero.StatUpdate ();
}
// Update is called once per frame
void Update ()
{
DisplayAttributes ();
}
void OnGUI()
{
DisplayName ();
DisplayPointsLeft ();
DisplayAttributes ();
DisplayVitals ();
DisplaySkills ();
}
private void DisplayName()
{
GUI.Label(new Rect(10, 10, 50, 25), "Name");
_hero.Name = GUI.TextField (new Rect (65, 10, 100, 25), _hero.Name);
}
private void DisplayAttributes()
{
for (int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++)
{
GUI.Label(new Rect(5, 50 + ((cnt + 4) * 20), 100, 20), ((AttributeName)cnt).ToString());
GUI.Label(new Rect(105, 50 + ((cnt + 4) * 20), 30, 20), _hero.GetPrimaryAttribute(cnt).AdjustedBaseValue.ToString());
if(GUI.Button(new Rect(105 + 30, 50 + ((cnt + 4) * 20), 20, 20), "-"));
{
if(_hero.GetPrimaryAttribute(cnt).BaseValue > MIN_STARTING_ATTRIBUTE_VALUE)
{
_hero.GetPrimaryAttribute(cnt).BaseValue--;
PointsLeft++;
_hero.StatUpdate ();
}
}
if(GUI.Button(new Rect(165, 50 + ((cnt + 4) * 20), 20, 20), "+"));
{
if(PointsLeft > 0)
{
_hero.GetPrimaryAttribute(cnt).BaseValue++;
PointsLeft--;
_hero.StatUpdate ();
}
}
}
}
private void DisplayVitals()
{
for (int cnt = 0; cnt < Enum.GetValues(typeof(VitalName)).Length; cnt++)
{
GUI.Label(new Rect(5, 50 + (cnt * 20), 100, 20), ((VitalName)cnt).ToString());
GUI.Label(new Rect(105, 50 + (cnt * 20), 30, 20), _hero.GetVital(cnt).AdjustedBaseValue.ToString());
}
}
private void DisplaySkills()
{
for (int cnt = 0; cnt < Enum.GetValues(typeof(SkillName)).Length; cnt++)
{
GUI.Label(new Rect(245, 50 + ((cnt + 4) * 20), 100, 20), ((SkillName)cnt).ToString());
GUI.Label(new Rect(325, 50 + ((cnt + 4) * 20), 30, 20), _hero.GetSkill(cnt).AdjustedBaseValue.ToString());
}
}
private void DisplayPointsLeft()
{
GUI.Label(new Rect(250,10, 100, 25), "Points Left: " + PointsLeft);
}
}
The pb here is the way you are announcing your problem, the title is not telling what is going on, the way you explain the problem (or not explaining it), the fact you throw your whole class without taking the time to isolate where it could be from. Even though you do not know where the issue is, you know where it does not come from, there are parts of your code that are irrelevant, don't post them. It is easier on us to help then.
First off you have DisplayAttributes called in the Update, it contains GUI methods so it won't work.
first off there are no errors... secondly i know that the problem lies somewhere in this class but i am not sure where, and yes i did put that in the update just to see if it would work.. it is fairly hard to isolate something that i cannot find, if i could find it i wouldn't be here.
but you are right i did not announce my problem correctly and i apologize it was quite late. the problem is that i click on the + and - buttons but it does not add or subtract from the attributes or from the points remaining. i at first assumed that this had something to do with the gui.button section however i rewrote that script from scratch and it still is not working.
"stopped giving me the quick option for GUI.label"
When monodev stops providing autocomplete functionality, it usually means there's a compile error. Which shows up in next to a big red icon in Unity's Console (Window > Console)
Answer by junkdog8 · May 20, 2014 at 08:48 PM
answer: don't put a ; at the end of your if statements...
Can't believe I missed that. $$anonymous$$y only excuse, and pretty weak at that, is my screen is not big enough to have the scroll bar and the if statement at the same time.
$$anonymous$$aybe next time you will only post the problem code and we can all get things sorted quicker. :) Glad you've got it working.
Your answer
Follow this Question
Related Questions
How to hook up the particle system to jump animation? 1 Answer
Make more buttons appear, on button click. 1 Answer
GUI Button Animation Cue 1 Answer
GUI window popup button 1 Answer
Android Button Screen 1 Answer