- Home /
does anyone know what is wrong with this script.
var normalTex : Texture2D;
var hoverTex : Texture2D;
var player_money : Rect = new Rect (0, 0, 0, 0);
static var ShopOn = false;
var InputText : GUIText;
private var inRange = false;
GameObject.FindGameObjectWithTag("con").gameObject.GetComponent("home_script").SetActive=false;
function OnMouseEnter () {;
guiTexture.texture = hoverTex;
}
function OnMouseExit(){
guiTexture.texture = normalTex;
}
function OnMouseDown(){
if(player_inventory.con_price >= player_inventory.player_money)
{
inRange = true;
InputText.text = "not enough money!";
yield WaitForSeconds(1.5);
{
print ("not enough funds");
}
}
else
if(player_inventory.player_money >= player_inventory.con_price)
{
print ("con bought");
player_inventory.player_money -= 33;
gameObject.Find("con_text").gameObject.GetComponent("home_script").gameObject.SetActive(true);
}
}
the error is in line gameObject.Find("con_text").gameObject.GetComponent("home_script").gameObject.SetActive(true); does anyone know what is wrong with the script?? i made sure it was spelt right
Comment
Answer by robertbu · Oct 01, 2014 at 11:04 PM
The line you indicate should be executed in a function. Start() would be a good place. And the line should be:
GameObject.FindGameObjectWithTag("con").GetComponent(home_script).SetActive=false;
No need for the extra 'gameObject', and no quotes around 'home_script'. I'm assuming that your 'home_script' has a variable called SetActive, and that you are not trying to use the GameObject.SetActive(). Or if you are trying to disable the script, it should be '.enabled = false'.
Your answer
![](https://koobas.hobune.stream/wayback/20220613164212im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
SetActive(true) not working 1 Answer
Boolean while looking at a game object? 1 Answer
Problems with save 1 Answer