- Home /
Script Not Working At All.... :) (SOLVED)
I have a bit of a problem... My Script won't work at all! xD I have it applied to my camera The whole Script is:
var Prefab : Transform;
function OnGui () {
if (GUI.Button(Rect(10,10,50,50),"Create")){
var gos : GameObject[];
gos = GameObject.FindGameObjectsWithTag("SetObject");
for (var g in gos){
if (g.GetComponent.<ControlObject>().isBuild);
Instantiate(Prefab, g.transform.position, Quaternion.identity);
}
}
}
I don't see anything wrong with it... I even tested to see if it was working by putting: 'Application.Quit();'
in the start function and it still didn't do anything :/ once again i have this script on my camera. Anyone have a idea on what may be causing this? Thanks if you can help! :D
Answer by Sjiggle · Jul 04, 2013 at 11:35 PM
well to start with, the following code:
if (g.GetComponent.<ControlObject>().isBuild);
does not actually do the code you'd expect afterwards. You exit the if, by adding ; at the end. Remove the ; and see if this fixes your code.
Also, I'd advice you to use indents more. It makes code more clear. For example:
var Prefab : Transform;
function OnGui () {
if (GUI.Button(Rect(10,10,50,50),"Create"))
{
var gos : GameObject[];
gos = GameObject.FindGameObjectsWithTag("SetObject");
for (var g in gos)
{
if (g.GetComponent.<ControlObject>().isBuild)
Instantiate(Prefab, g.transform.position, Quaternion.identity);
}
}
}
no :/ didn't make a difference. Thanks for the advice though xD
You are also using the wrong function name. You use OnGui. It's function OnGUI() {
Oh $$anonymous$$y gosh i can be a idiot some times :P thanks so much, worked perfectly. guess i was na$$anonymous$$g the start function wrong too :P
And what did you mean by: "if (g.GetComponent.().isBuild); does not actually do the code you'd expect afterwards"?
Because what i was trying to do before this problem isn't working :P