- Home /
GUI Label/Text Area Doesn't Show Up Inside Scrollview
After I read some documents on how to make a simple scrollview and added some contents inside scrollview is quite straightforward and it worked. Now, I decided to add some GUI text or label to add this onto the scrollview. When I run it, it appears blank. Here's the code.
void OnGUI() {
scrollPosition = GUI.BeginScrollView(new Rect(0, (Adjust.getButtonSquare(false, true, 16)/2) - (Adjust.getButtonSquare(false, true, 14)/2), Adjust.getButtonSquare(true, false, 10), Adjust.getButtonSquare(false, true, 14)), scrollPosition, new Rect(0, Adjust.getButtonSquare(true, false, 10), 220, 1200));
GUI.DrawTexture (new Rect(0, 0, 9999, 9999), guiTexture.texture);
string text = GUI.TextArea(new Rect(10, 10, 209, 209),
"Top-left \n" +
"Top-left " +
"\nTop-left " +
"\nTop-left " +
"\nTop-left " +
"\nTop-left " +
"\nTop-left " +
"\nTop-left " +
"\nTop-left " +
"\nTop-left " +
"\nTop-left \n");
// text [0].transform.position = new Vector3 (0, 0, 0);
// GUI.Button(new Rect(120, 0, 100, 20), "Top-right");
// GUI.Button(new Rect(0, 180, 100, 20), "Bottom-left");
// GUI.Button(new Rect(120, 180, 100, 20), "Bottom-right");
GUI.EndScrollView();
}
UPDATE: By the way, if you're wondering where did I get this such code/method under Rect
parameters and those are static return variables from Adjust.cs
code. Here's the preview so you can understand its reference.
using UnityEngine;
using System.Collections;
/**
*
* Script behavior for GUI position and size.
*
*/
public class Adjust : MonoBehaviour {
public bool setToLandscape = false;
public static bool setToLandscapeStatic; // --> To be used for sharing reference.
void Start() {
setToLandscape = setToLandscapeStatic;
}
public static float GetButtonWidth() {
if(setToLandscapeStatic) {
return (Screen.width/16) * 7;
} else {
return (Screen.width/10) * 6;
}
}
public static float GetButtonHeight() {
if(setToLandscapeStatic) {
return (Screen.height/10) * 0.25f;
} else {
return (Screen.height/16) * 1.25f;
}
}
public static float GetLocationX(float x) {
if(setToLandscapeStatic) {
return (Screen.width/16) * x;
} else {
return (Screen.width/10) * x;
}
}
public static float GetLocationY(float y) {
if(setToLandscapeStatic) {
return (Screen.height/10) * y;
} else {
return (Screen.height/16) * y;
}
}
public static float getButtonSquare(bool width, bool height, float value) {
if(height) {
return GUI.skin.button.fixedHeight = (Screen.height/16) * value;
} else if(width) {
return GUI.skin.button.fixedWidth = (Screen.width/10) * value;
} else {
return (Screen.height/16) * value;
}
}
public static float getButtonSquare() {
return (Screen.height/16) * 2;
}
}
Answer by David_29 · Jul 22, 2014 at 06:34 AM
I found the error and something had to fix on the third parameter of GUI.BeginScrollView
. I have to set the TOP position of the 'Rect' to 0.
BEFORE
scrollPosition = GUI.BeginScrollView(new Rect(0, (Adjust.getButtonSquare(false, true, 16)/2) - (Adjust.getButtonSquare(false, true, 14)/2), Adjust.getButtonSquare(true, false, 10), Adjust.getButtonSquare(false, true, 14)), scrollPosition, new Rect(0, Adjust.getButtonSquare(true, false, 10), 220, 1200));
AFTER
scrollPosition = GUI.BeginScrollView(new Rect(0, (Adjust.getButtonSquare(false, true, 16)/2) - (Adjust.getButtonSquare(false, true, 14)/2), Adjust.getButtonSquare(true, false, 10), Adjust.getButtonSquare(false, true, 14)), scrollPosition, new Rect(0, 0, 220, 1200));
Your answer
Follow this Question
Related Questions
GUI.TextField - Android: Unfocusing with click instead of Ok-button causes critical error 0 Answers
4.6 GUI Button inside a scrolling Text Box 0 Answers
Why is my scrollview jittering? 1 Answer
GUI Windows not being removed properly in a network 1 Answer
How can I combine a Mask with a Scroll Rect to limit the visible content? 2 Answers