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
" +
"Top-left " +
"
Top-left " +
"
Top-left " +
"
Top-left " +
"
Top-left " +
"
Top-left " +
"
Top-left " +
"
Top-left " +
"
Top-left " +
"
Top-left
");
// 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;
}
}