public class Toolbar : MonoBehaviour { public static bool leftClick; [System.Serializable] public class ButtonsClass { public bool MouseOver; public Vector2 ButtonSize; public Vector2 ButtonPosition; public Texture2D ButtonTexture; public Texture2D HighlightTexture; Texture2D CurrentTexture; public enum ButtonType { Color, Direction, Orientation, Object } public ButtonType Type; public string Name; public Rect ButtonRect() { return new Rect((int)(ButtonPosition.x * (Screen.height * 0.01f)), // Left (int)(ButtonPosition.y * (Screen.height * 0.01f)), // Top (int)(ButtonSize.x * (Screen.height * 0.01f)), // Width (int)(ButtonSize.y * (Screen.height * 0.01f))); // Height } public Rect ButtonRect(int xMulti) { return new Rect((int)((ButtonPosition.x*xMulti) * (Screen.height * 0.01f)), // Left (int)(ButtonPosition.y * (Screen.height * 0.01f)), // Top (int)(ButtonSize.x * (Screen.height * 0.01f)), // Width (int)(ButtonSize.y * (Screen.height * 0.01f))); // Height } public void DrawButton() { CheckMouse(1); GUI.DrawTexture(ButtonRect(), CurrentTexture, ScaleMode.StretchToFill, true); } public void DrawButton(int xMultiply) { CheckMouse(xMultiply); GUI.DrawTexture(ButtonRect(xMultiply), CurrentTexture, ScaleMode.StretchToFill, true); } void CheckMouse(int xMulti) { Vector2 MousePos = new Vector2(Input.mousePosition.x-2,((Input.mousePosition.y - Screen.height) * -1)-2); // Gives us an easier to use variable if (MousePos.x > ButtonRect(xMulti).x & MousePos.y > ButtonRect(xMulti).y & MousePos.x < ButtonRect(xMulti).xMax & MousePos.y < ButtonRect(xMulti).yMax) { CurrentTexture = HighlightTexture; if (leftClick) { ButtonClicked(); leftClick = false; } } else { CurrentTexture = ButtonTexture; } } void ButtonClicked() { switch (Type) { case ButtonType.Color: SetColor(Name); // Fix this tomorrow break; default: Debug.Log("No type selected."); break; } } } public void SetColor(string recievedName) { switch (recievedName) { case "red": break; default: Debug.Log("Color name invalid."); break; } } }