Compnent.guiTexture is obsolete

I have just reopened an old project from Unity 4, and recieved quite a few errors in Unity 5. It is my play button, and even trying to use GetComponent() doesnt seem to fix it. here are the errors.

Assets/Scripts/PlayButton.js(11,9): BCE0144: ‘UnityEngine.Component.guiTexture’ is obsolete. Property guiTexture has been deprecated. Use GetComponent() instead. (UnityUpgradable)

Assets/Scripts/PlayButton.js(11,20): BCE0019: ‘texture’ is not a member of ‘UnityEngine.Component’.

Assets/Scripts/PlayButton.js(16,9): BCE0144: ‘UnityEngine.Component.guiTexture’ is obsolete. Property guiTexture has been deprecated. Use GetComponent() instead. (UnityUpgradable)

Assets/Scripts/PlayButton.js(16,20): BCE0019: ‘texture’ is not a member of ‘UnityEngine.Component’.

Here is my simple script, How can i fix the errors?

#pragma strict
var playNormal : Texture2D;
var playHover : Texture2D;

function Start () {


function OnMouseEnter ()
	guiTexture.texture = playHover;

function OnMouseExit ()
	guiTexture.texture = playNormal;

function OnMouseDown ()

using UnityEngine;

public class TestScript : MonoBehaviour
	public Texture2D playNormal;
	public Texture2D playHover;

	private new GUITexture guiTexture;

	void Start () 
		guiTexture = GetComponent<GUITexture>();

	// Rest of your code.

Use this code. It will automatically add a GUITexture component to your GameObject if there is none. Then it creates a variable for the GUITexture. In past years, there was an automatic property for this, but since the GUITexture and old OnGUI System is being replaced by the new Unity UI, the properties are becoming obsolete. If you really need that component for some reason, use my code. The “new” keyword will override the inherited (but obsolete) property “guiTexture”. It is still in Unitys codebase for documentation and to give instruction on how to make old project compatible.

Other than that, I would advise to look at the brand new UI System, which is very powerful: Unity official tutorials - UI

PS: Also, if you’re using the old GUITexture component, the image you feed into it, must be marked as “Legacy GUI” I believe.