3DPlatformTutorial - GUI Scripting error

Alright I have started the 3Dplatformtutorial, and I’m on page 54-55, I added the script GameHUD, however on the screen I still do not see the HUD appearing over the play area, here’s log information:

(Filename: Assets/Scripts/GUI/GameHUD.js Line: 40)

NullReferenceException: Object reference not set to an instance of an object
at GameHUD.OnGUI () [0x00000] in C:\Documents and Settings\gucci\My Documents\New Unity Project\3DPlatformTutorialStart\Assets\Scripts\GUI\GameHUD.js:40
UnityEditor.EditorGUIUtility:INTERNAL_CALL_RenderGameViewCameras(Rect, Rect, Boolean, Boolean)
UnityEditor.EditorGUIUtility:RenderGameViewCameras(Rect, Rect, Boolean, Boolean) (at E:\BuildAgent\work\71ca6fec1b41cc30\Editor\Mono\Generated\EditorGUIUtility.cs:382)
UnityEditor.GameView:OnGUI() (at E:\BuildAgent\work\71ca6fec1b41cc30\Editor\Mono\GameView\GameView.cs:421)
System.Reflection.MonoMethod:InternalInvoke(Object, Object[ ], Exception)
System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[ ], CultureInfo)
System.Reflection.MethodBase:Invoke(Object, Object[ ])
UnityEditor.HostView:Invoke(String, Object) (at E:\BuildAgent\work\71ca6fec1b41cc30\Editor\Mono\GUI\DockArea.cs:212)
UnityEditor.HostView:Invoke(String) (at E:\BuildAgent\work\71ca6fec1b41cc30\Editor\Mono\GUI\DockArea.cs:205)
UnityEditor.DockArea:OnGUI() (at E:\BuildAgent\work\71ca6fec1b41cc30\Editor\Mono\GUI\DockArea.cs:630)

The GUI SCRIPT Code is here:

// GameHUD: Platformer Tutorial Master GUI script.

// This script handles the in-game HUD, showing the lives, number of fuel cells remaining, etc.

var guiSkin: GUISkin;
var nativeVerticalResolution = 1200.0;

// main decoration textures:
var healthImage: Texture2D;
var healthImageOffset = Vector2(0, 0);

// the health 'pie chart' assets consist of six textures with alpha channels. Only one is ever shown:
var healthPieImages : Texture2D[];
var healthPieImageOffset = Vector2(10, 147);

// the lives count is displayed in the health image as a text counter
var livesCountOffset = Vector2(425, 160);

// The fuel cell decoration image on the right side
var fuelCellsImage: Texture2D;
var fuelCellOffset = Vector2(0, 0);

// The counter text inside the fuel cell image
var fuelCellCountOffset = Vector2(391, 161);

private var playerInfo : ThirdPersonStatus;

// Cache link to player's state management script for later use.
function Awake()
{
	playerInfo = FindObjectOfType(ThirdPersonStatus);

	if (!playerInfo)
		Debug.Log("No link to player's state manager.");
}

function OnGUI ()
{

	var itemsLeft = playerInfo.GetRemainingItems();	// fetch items remaining -- the fuel cans. This can be a negative number!

	// Similarly, health needs to be clamped to the number of pie segments we can show.
	// We also need to check it's not negative, so we'll use the Mathf Clamp() function:
	var healthPieIndex = Mathf.Clamp(playerInfo.health, 0, healthPieImages.length);

	// Displays fuel cans remaining as a number.	
	// As we don't want to display negative numbers, we clamp the value to zero if it drops below this:
	if (itemsLeft < 0)
		itemsLeft = 0;

	// Set up gui skin
	GUI.skin = guiSkin;

	// Our GUI is laid out for a 1920 x 1200 pixel display (16:10 aspect). The next line makes sure it rescales nicely to other resolutions.
	GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (Screen.height / nativeVerticalResolution, Screen.height / nativeVerticalResolution, 1)); 

	// Health  lives info.
	DrawImageBottomAligned( healthImageOffset, healthImage); // main image.

	// now for the pie chart. This is where a decent graphics package comes in handy to check relative sizes and offsets.
	var pieImage = healthPieImages[healthPieIndex-1];
	DrawImageBottomAligned( healthPieImageOffset, pieImage );
	
	// Displays lives left as a number.	
	DrawLabelBottomAligned( livesCountOffset, playerInfo.lives.ToString() );	
	
	// Now it's the fuel cans' turn. We want this aligned to the lower-right corner of the screen:
	DrawImageBottomRightAligned( fuelCellOffset, fuelCellsImage);

	DrawLabelBottomRightAligned( fuelCellCountOffset, itemsLeft.ToString() );
}

function DrawImageBottomAligned (pos : Vector2, image : Texture2D)
{
	GUI.Label(Rect (pos.x, nativeVerticalResolution - image.height - pos.y, image.width, image.height), image);
}

function DrawLabelBottomAligned (pos : Vector2, text : String)
{
	GUI.Label(Rect (pos.x, nativeVerticalResolution - pos.y, 100, 100), text);
}

function DrawImageBottomRightAligned (pos : Vector2, image : Texture2D)
{
	var scaledResolutionWidth = nativeVerticalResolution / Screen.height * Screen.width;
	GUI.Label(Rect (scaledResolutionWidth - pos.x - image.width, nativeVerticalResolution - image.height - pos.y, image.width, image.height), image);
}

function DrawLabelBottomRightAligned (pos : Vector2, text : String)
{
	var scaledResolutionWidth = nativeVerticalResolution / Screen.height * Screen.width;
	GUI.Label(Rect (scaledResolutionWidth - pos.x, nativeVerticalResolution - pos.y, 100, 100), text);
}

I’m assuming its maybe the script needs changes because my Unity version is 3.10f4?
Help asap will be appreciated, thanks.

Are you sure that’s the only log output? Line 40 of that script is using playerInfo, which is set in Awake(). Awake() logs a message if setting playerInfo fails, which you should see in the log before the NullReferenceException. Assuming you do see that, you need to check what step of the tutorial you may have missed that results in there not being a ThirdPersonStatus object in the scene.

Thats the problem I don’t think I Missed anything, I dragged the script on top of “Level” in Hierachy, and right after it asks you to play the game to see the HUD, I do not see that, help will be appreciated :frowning:
and here’s an attachment of the whole log file, since I’m not sure what to paste and its too big to paste it all, I also had to put it in a rar file, no viruses help will be appreciated asap, thanks.

451164–15721–$oldEditor.rar (20.3 KB)

Also, here’s a screenshot, not only that I dont see the HUD, but my character is flying which I think it shouldnt be like that ? here’s a screenshot to refer to what I’m saying, where can I fix that error ?? I tried lowering the Lerpz from where he starts but than he elevates a bit after game start :slight_smile:
PS: I played with the vertical resolution but now its back to default.

O M G, hahah fixed, I have fixed the GUI error !!!, now I only need help with my Lerpz character to be actually touching the ground instead of flying, any help ?? thanks.

I know this is an post, but I had the same issue and realized I had forgotten to include Third Person Status script.

The “Flying Lerpz” issue is a common one too: it’s usually caused by the “capsule collider” component.

If you click on “Lerpz” in the Scene Editor, you should see a capsule-shaped collider (normally a yellow wireframe). This is what is used to check when Lerpz touches other elements of the scene, including the platforms themselves. If the capsule is offset below the character model, Lerpz will appear to be flying.

To fix the problem, change the capsule collider’s own “y” coordinate to move it back up over Lerpz. I find changing this from “0” to “1” works fine.