Help with Gui Skins

Hey there, I’ve been trying out the RPG inventory system you may have seen over at the Showcase forum, and I wanted to Put in a custom skin. So I looked up the documentation and it said All I had to do was put in this code after the function.OnGui(){

GUI.skin = customSkin;

(with customSkin being the name of my skin)

I tried this and received many errors. Including

Assets/Scripts/Inventory.js(128,20): BCE0005: Unknown identifier: 'customSkin'.
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.GUISkin.BuildStyleCache () 
UnityEngine.GUISkin.OnValidate () 
UnityEngine.ScriptableObject:.ctor()
UnityEngine.ScriptableObject:.ctor()
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.GUISkin.BuildStyleCache () 
UnityEngine.GUISkin.OnValidate () 
UnityEngine.ScriptableObject:.ctor()
UnityEngine.ScriptableObject:.ctor()

Sorry if I sound a bit stupid about this stuff, I only have limited knowledge of C#. Here is the script

function OnGUI()
{       GUI.skin = customSkin;
	ix = Input.mousePosition.x; 
	iy = Input.mousePosition.y; 
	GUI.matrix = Matrix4x4.TRS (Vector3.zero, Quaternion.identity, Vector3(Screen.width / 1024.0, Screen.height / 768.0, 1)); 
	var transMouse = GUI.matrix.inverse.MultiplyPoint3x4(Vector3(ix, Screen.height - iy, 1)); 

	//GUI.DrawTexture (Rect(0,0,1024,768),emptyTex);
	
	GUI.Label (Rect (800, 20, 200, 20), "Fullscreen:");
	if (GUI.Button (Rect (880, 20, 50, 20), togglefullscreen)) { 
		Screen.fullScreen = !Screen.fullScreen;
		if (togglefullscreen == "On"){
			togglefullscreen = "Off";
		}
		else
		{
			togglefullscreen = "On";
		}
	}

(that isnt where it ends, its a long code, but it is the part that is mucking up. If you need the entire thing, I can show it.
thanks for your help

do you have customSkin defined somewhere? If not, that would cause the problem you have.

I added a custom skin called customSkin Using the add button. Do I need to define it somehow somewhere else?

Sort of. You made a GUISkin called “customSkin.”
then you used a variable customSkin. This is not the same as the Skin called “customSkin”. You need to define the variable. In the example below, I call the variable mySkin to avoid confusion with the “customSkin.”

//define it here
var GUISkin : mySkin
function OnGUI()
{
  //use it here       
  GUI.skin = mySkin;

and you need to drag your “customSkin” onto the newly created mySkin variable that you will see in the inspector.

If this doesn’t make sense, I’d suggest taking a step back, searching through the fourms for some scripting tutorials and going through those first.

Ok, So I have this

	var GUISkin : mySkin


function OnGUI()
{	GUI.skin = MySkin;
[CODE]
(with all of my stuff around it.)
And I still get 2 "NullReferenceException: Object reference not set to an instance of an object" and when I click on them, it highlights the GUI skin.
  • MySkin is not the same as mySkin, variables names are case sensitive
  • did you dragndrop the your custom Skin onto the inspector entry for mySkin?

Ok, I corrected the name error. But Im still getting the errors. Im not sure what you mean. My custom Skin is called MySkin, if that’s what you mean.

OK, I can see you are still a little confused. The name of the variable has nothing to do with the name of your custom skin. they are unrelated. I suggest you start with something a little simpler. What you are doing is not complicated but you need some foundation. I think it will click for you pretty quickly. This is a good place to start:

http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)?highlight=long+scripting