So I’m working on a game in Unity using javascript. My problem is I can’t seem to figure out how to activate a GUITexture that is not attactched to the certain texture (External Script).
So here I have my script for my button which is called Upgrade.js
var normalTexture : Texture;
var hoverTexture : Texture;
var pressedTexture : Texture;
var messagee : GameObject;
var message = "ButtonPressed";
private var state = 0;
private var myGUITexture : GUITexture;
myGUITexture = GetComponent(GUITexture);
function OnMouseEnter()
{
state++;
if (state == 1)
myGUITexture.texture = hoverTexture;
}
function OnMouseDown()
{
state++;
if (state == 2)
myGUITexture.texture = pressedTexture;
var window = gameObject.Find("WindowUpgrade");
if(window.active == false){
window.setActive = true;
}
}
function OnMouseUp()
{
if (state == 2)
{
state--;
if (messagee)
messagee.SendMessage(message, gameObject);
}
else
{
state --;
if (state < 0)
state = 0;
}
myGUITexture.texture = normalTexture;
}
function OnMouseExit()
{
if (state > 0)
state--;
if (state == 0)
myGUITexture.texture = normalTexture;
}
The problem is with the OnMouseDown function!
Here is the other script, CloseBox.js:
#pragma strict
function Update(){
if (Input.GetKeyDown("c")){
guiTexture.active = false;
}
}
The error I get is “NullReferenceException: object reference not set to an instance of an object”
Any help is much appreciated!
Thanks!
-Lucas Springsteen