Hey Alright i figured out i could not use the Canvas. so i have coded the stuff for a script so like i have a barracks and coded a script for that… that will use the buttons etc… the problem is that the script compiles but the buttons do not show up…
HUD_Barracks.cs
using UnityEngine;
using System.Collections;
public class HUD_Barracks : MonoBehaviour
{
//Spawn Location
public Transform spawn;
public Transform goToAfterSpawn;
//public Player
private PlayerScript Usercube;
//public Resources
private Resources UserResources;
//Icons
public Texture2D icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8, icon9, icon10, icon11, icon12, icon13, icon14, icon15, icon16, icon17, icon18;
//drag Selection
public bool selected = false;
//private Vector3 moveToDest = Vector3.zero;
public float floorOffSet = 1;
//Click Select
private bool selectionByClick = false;
// Use this for initialization
void Start ()
{ //using scripts attached to User
GameObject user = GameObject.Find("UserCube");
//usings Stuff from PlayerScript Script
PlayerScript Usercube = user.GetComponent<PlayerScript>();
//usings Stuff from Resources Script
Resources UserResources = user.GetComponent<Resources>();
}
void OnGUI()
{
if(Usercube && Usercube.human) //checks to see if user is human
{
DrawButtons();
}
}
// Update is called once per frame
private void Update ()
{
//Place Layer Unit Control Here.
if (Input.GetMouseButton(0))
{
if (!selectionByClick)
{
Vector3 camPos = Camera.main.WorldToScreenPoint (transform.position);
camPos.y = CamOP.InvertMouseY(camPos.y);
selected = CamOP.selection.Contains (camPos);
}
if (selected)
{
gameObject.GetComponentInChildren<Projector>().enabled = true;
}
else
{
gameObject.GetComponentInChildren<Projector>().enabled = false;
}
}
}
//buttons for barracks
private void DrawButtons()
{
// Make a group
GUI.BeginGroup (new Rect (Screen.width - 310,Screen.height - 270,300,260));
// All rectangles are now adjusted to the group. (0,0) is the topleft corner of the group.
//(0__PositionWidth,0__PositionHeight,0__BOXWidth,0__BOXHeight)
//Row1---------------------------------------------------------------------------------------------------------------------------------
//Button1
GUI.RepeatButton (new Rect (0,80,60,60), new GUIContent ("", icon1, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button2
GUI.RepeatButton (new Rect (60,80,60,60), new GUIContent ("", icon2, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button3
GUI.RepeatButton (new Rect (120,80,60,60), new GUIContent ("", icon3, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button4
GUI.RepeatButton (new Rect (180,80,60,60), new GUIContent ("", icon4, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button5
GUI.RepeatButton (new Rect (240,80,60,60), new GUIContent ("", icon5, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button6
GUI.RepeatButton (new Rect (300,80,60,60), new GUIContent ("", icon6, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Row2---------------------------------------------------------------------------------------------------------------------------------
//Button7
GUI.RepeatButton (new Rect (0,140,60,60), new GUIContent ("", icon7, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button8
GUI.RepeatButton (new Rect (60,140,60,60), new GUIContent ("", icon8, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button9
GUI.RepeatButton (new Rect (120,140,60,60), new GUIContent ("", icon9, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button10
GUI.RepeatButton (new Rect (180,140,60,60), new GUIContent ("", icon10, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button11
GUI.RepeatButton (new Rect (240,140,60,60), new GUIContent ("", icon11, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button12
GUI.RepeatButton (new Rect (300,140,60,60), new GUIContent ("", icon12, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Row3---------------------------------------------------------------------------------------------------------------------------------
//Button13
GUI.RepeatButton (new Rect (0,200,60,60), new GUIContent ("", icon13, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button14
GUI.RepeatButton (new Rect (60,200,60,60), new GUIContent ("", icon14, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button15
GUI.RepeatButton (new Rect (120,200,60,60), new GUIContent ("", icon15, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button16
GUI.RepeatButton (new Rect (180,200,60,60), new GUIContent ("", icon16, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button17
GUI.RepeatButton (new Rect (240,200,60,60), new GUIContent ("", icon17, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button18
GUI.RepeatButton (new Rect (300,200,60,60), new GUIContent ("", icon18, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
// End the group we started above.
GUI.EndGroup ();
}
//Function for SimpleMouseClick
private void OnMouseDown()
{
selectionByClick = true;
selected = true;
}
private void OnMouseUp()
{
if (selectionByClick)
selected = true;
selectionByClick = false;
}
}
now HUD CS is where i got it working and it works fine…
using UnityEngine;
using System.Collections;
public class HUD : MonoBehaviour {
//public Player
private PlayerScript User;
//Icons
public Texture2D icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8, icon9, icon10, icon11, icon12, icon13, icon14, icon15, icon16, icon17, icon18;
// Use this for initialization
void Start ()
{
User = transform.root.GetComponent< PlayerScript >();
}
// Update is called once per frame
void OnGUI()
{
if(User && User.human) //checks to see if user is human
{
DrawMiniMap();
DrawResourceBar();
DrawButtons();
}
}
//Creates the OrderBar for HUD
private void DrawMiniMap()
{
GUI.Box (new Rect (10,Screen.height - 110,100,100), "MiniMap");
}
//creates the ResourceBar for HUD
private void DrawResourceBar()
{
//resources go here
}
private void DrawButtons()
{
// Make a group on the center of the screen
GUI.BeginGroup (new Rect (Screen.width - 310,Screen.height - 270,300,260));
// All rectangles are now adjusted to the group. (0,0) is the topleft corner of the group.
//(0__PositionWidth,0__PositionHeight,0__BOXWidth,0__BOXHeight)
//Row1---------------------------------------------------------------------------------------------------------------------------------
//Button1
GUI.RepeatButton (new Rect (0,80,60,60), new GUIContent ("", icon1, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button2
GUI.RepeatButton (new Rect (60,80,60,60), new GUIContent ("", icon2, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button3
GUI.RepeatButton (new Rect (120,80,60,60), new GUIContent ("", icon3, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button4
GUI.RepeatButton (new Rect (180,80,60,60), new GUIContent ("", icon4, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button5
GUI.RepeatButton (new Rect (240,80,60,60), new GUIContent ("", icon5, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button6
GUI.RepeatButton (new Rect (300,80,60,60), new GUIContent ("", icon6, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Row2---------------------------------------------------------------------------------------------------------------------------------
//Button7
GUI.RepeatButton (new Rect (0,140,60,60), new GUIContent ("", icon7, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button8
GUI.RepeatButton (new Rect (60,140,60,60), new GUIContent ("", icon8, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button9
GUI.RepeatButton (new Rect (120,140,60,60), new GUIContent ("", icon9, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button10
GUI.RepeatButton (new Rect (180,140,60,60), new GUIContent ("", icon10, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button11
GUI.RepeatButton (new Rect (240,140,60,60), new GUIContent ("", icon11, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button12
GUI.RepeatButton (new Rect (300,140,60,60), new GUIContent ("", icon12, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Row3---------------------------------------------------------------------------------------------------------------------------------
//Button13
GUI.RepeatButton (new Rect (0,200,60,60), new GUIContent ("", icon13, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button14
GUI.RepeatButton (new Rect (60,200,60,60), new GUIContent ("", icon14, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button15
GUI.RepeatButton (new Rect (120,200,60,60), new GUIContent ("", icon15, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button16
GUI.RepeatButton (new Rect (180,200,60,60), new GUIContent ("", icon16, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button17
GUI.RepeatButton (new Rect (240,200,60,60), new GUIContent ("", icon17, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
//Button18
GUI.RepeatButton (new Rect (300,200,60,60), new GUIContent ("", icon18, "This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf This is the tooltip1 asdfasdf asdf asdf asd fas df asdf asdf asdf"));
GUI.Label (new Rect (0,0,290,80), GUI.tooltip);
// End the group we started above. This is very important to remember!
GUI.EndGroup ();
}
}
but the minute i try place it in the barracks script nothing…

