I’m trying to change Font/color on a GUI in Unity. Here is my code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Menu : MonoBehaviour
{
public int MenuWidth;
public int MenuHeight;
public Texture Image;
public GUIStyle GUIStyle; // set the text style of the frame counter
Rect MenuRect;
// Create a public variable where we can assign the GUISkin
var customSkin : GUISkin;
// Start is called before the first frame update
void Start()
{
if ((MenuWidth == 0) || (MenuHeight == 0))
{
Debug.Log(“Menu size isn’t set”);
}
MenuRect = new Rect(Screen.width / 2 - MenuWidth / 2, Screen.height / 2 - MenuHeight / 2, MenuWidth, MenuHeight);
}
// Update is called once per frame
void Update()
{
}
private void OnGUI()
{
GUI.skin = customSkin;
GUI.Box(MenuRect, “Main Menu”);
GUI.DrawTexture(new Rect(Screen.width / 2 - 30, MenuRect.yMin + 30, 50, 50), Image);
if (GUI.Button(new Rect(MenuRect.xMin + 20, MenuRect.yMin + 130, MenuRect.width - 100, 100), “PLAY”))
{
SceneManager.LoadScene(1);
}
if (GUI.Button(new Rect(MenuRect.xMin + 20, MenuRect.yMin + 225, MenuRect.width - 50, 100), “QUIT”))
{
Application.Quit();
}
}
}
I’m trying to use GUISkin, but I keep getting errors, any tips from anyone?