Here is the entire script, I have added this script to an empty game object. It runs the script, but the GUIScrollBar is always empty. As you can see, I tried many variations, this is more conceptual to me. Is there anything obvious missing? Is it supposed to just run my components code or do I need to instantiate it?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using System.Collections;
using Test.Assets.Component.GameManager.Business;
public class GUIScrollBar : MonoBehaviour
//public class test : MonoBehaviour
{
//public GUIScrollBar gUIScrollBar;
private GUIScrollBar gUIScrollBar;
public Texture2D progressBarEmpty;
public Texture2D progressBarFull;
public void Awake()
{
//Get gameobject by name
var go = GameObject.Find(“GCTest”);
//gUIScrollBar = (GUIScrollBar)go.GetComponent(“Test”); //.GetComponent(typeof(GUIScrollBar));
// print(gUIScrollBar.name);
//print(gUIScrollBar.barDisplay.ToString());
//gUIScrollBar.OnGUI();
//gUIScrollBar = (GUIScrollBar)go.GetComponent(typeof(GUIScrollBar));
// var go2 = GameObject.Find(“GUIScrollBar”);
// print(go2.tag);
/////////////gUIScrollBar = (GUIScrollBar)gameObject.GetComponent(typeof(GUIScrollBar));
//gUIScrollBar = gameObject.AddComponent();
//////////////// gUIScrollBar = (GUIScrollBar)gameObject.GetComponent(typeof(GUIScrollBar));
var x = GetComponent(“GUIScrollBar”);
print(x.name);
// gUIScrollBar = (GUIScrollBar)gameObject.AddComponent(“GUIScrollBar”);
///var test = (GUIScrollBar)gameObject.AddComponent(“GUIScrollBar”);
// gUIScrollBar.OnGUI();
//print(“hello”);
// gUIScrollBar.barDisplay = 60;
// gUIScrollBar.progressBarEmpty = progressBarEmpty;
// gUIScrollBar.progressBarFull = progressBarFull;
}
//This code is the code in the component below and it works if I run it here
public void OnGUI()
{
//////////////// gUIScrollBar.OnGUI();
// gUIScrollBar = gameObject.AddComponent(); //???
/// gUIScrollBar.barDisplay = 60;
//////// // draw the background:
//////// GUI.BeginGroup(new Rect(pos.x, pos.y, size.x, size.y));
//////// GUI.Box(new Rect(0, 0, size.x, size.y), progressBarEmpty);
//////// // draw the filled-in part:
//////// GUI.BeginGroup(new Rect(0, 0, size.x * barDisplay, size.y));
//////// GUI.Box(new Rect(0, 0, size.x, size.y), progressBarFull);
//////// GUI.EndGroup();
//////// GUI.EndGroup();
////////// GUI.Box(new Rect(10, 10, 100, 90), “Test text”);
}
}