Hai guys, I have one box in the scene and when the box is trigger by the player, I want to add a text to the `GUILayout.Label`. But I got this following error: `ArgumentException: Getting control 0's position in a group with only 0 controls when doing Repaint`.
Here is the code that I am using:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class QuestManager : MonoBehaviour
{
public static bool acceptedChiefQuest = false;
private List someTexts = new List();
private Vector2 scrollPosition = Vector2.zero;
private Rect windowRect = new Rect();
private GUIStyle style = null;
public AudioClip audioSEClip = null;
private void Start()
{
windowRect = GameManager.WindowScreen(Screen.width - 350, 365);
AddingQuest("Talk to the chief");
}
private void SetStyle()
{
// Set the style
style = new GUIStyle(GUI.skin.label);
// Set the text alignment
style.alignment = TextAnchor.MiddleLeft;
// Set the word wrap
style.wordWrap = true;
// Set the font style
style.fontStyle = FontStyle.BoldAndItalic;
// Set the font size
style.fontSize = 11;
}
private void OnGUI()
{
SetStyle();
if (!CheckPlayer.isOnChat)
{
windowRect = GUILayout.Window(2, windowRect, ConsoleWindow, string.Empty, style);
}
if (acceptedChiefQuest)
{
RemovingQuest("Talk to the chief");
AddingQuest("Accepted the quest from the chief"); // Argument Error in this line
}
}
private void ConsoleWindow(int id)
{
scrollPosition = GUILayout.BeginScrollView(scrollPosition);
for (int i = 0; i < someTexts.Count; i++)
{
GUILayout.Label("Quest Description: " + someTexts[i], style);
}
GUILayout.EndScrollView();
}
private void AddingQuest(string message)
{
someTexts.Add(message);
audio.PlayOneShot(audioSEClip);
}
private void RemovingQuest(string message)
{
someTexts.Remove(message);
}
}
And here is the script when the box is triggered by the player:
using UnityEngine;
using System.Collections;
public class Dialog : MonoBehaviour
{
private void OnTriggerEnter(Collider obj)
{
if (obj.gameObject.tag == "Portal Chief")
{
QuestManager.acceptedChiefQuest = true;
}
}
}
How can I fix this?
Your answer much appreciated!
Thank you very much!
↧