- Home /
Button Script issue, works in game mode not in build and run
this script is on my button GUITexture
var rolloverTexture : Texture2D; var normalTexture : Texture2D; var noTexture : Texture2D; var Dragon : GameObject; static var thisGameStart : boolean = false;
function OnMouseEnter(){
if(thisGameStart==false){
guiTexture.texture = rolloverTexture;
}
}
function OnMouseExit(){
if(thisGameStart==false){
guiTexture.texture = normalTexture;
}else{
guiTexture.texture=noTexture;
}
}
function OnMouseUp () {
var TargetScript : DragonGameIntro = gameObject.GetComponent(DragonGameIntro);
TargetScript.attack = true;
thisGameStart = true;
guiTexture.texture = noTexture;
}
this script is on a dragon that circles until the button is clicked then moves toward the target located near the camera
static var attack : boolean = false; var MoveTarget : GameObject; var MoveTimer : float = 0; var emitter1 : GameObject; var emitter2 : GameObject; var emitter3 : GameObject; var light1 : GameObject;
emitter1 = gameObject.Find("OuterCore");
emitter2 = gameObject.Find("InnerCore");
emitter3 = gameObject.Find("Smoke");
light1 = gameObject.Find("Lightsource");
var FireSound : AudioClip;
function Update () {
if(attack==false){
gameObject.transform.Rotate(0,.5,0);
gameObject.transform.Translate(0,0,.3);
emitter1.particleEmitter.emit=false;
emitter2.particleEmitter.emit=false;
emitter3.particleEmitter.emit=false;
light1.light.enabled=false;
}
if(attack==true){
MoveTimer++;
is_breathingfire=true;
if(is_breathingfire==true){
PlaySound(FireSound);
emitter1.particleEmitter.emit=true;
emitter2.particleEmitter.emit=true;
emitter3.particleEmitter.emit=true;
light1.light.enabled=true;
}
transform.LookAt(MoveTarget.transform);
transform.position = Vector3.Lerp(transform.position,MoveTarget.transform.position,Time.deltaTime * .6);
var Dist : float = Vector3.Distance(transform.position,MoveTarget.transform.position);
if(Dist<4){
NextLevel();
}
}
}
function PlaySound(currentSound){
audio.PlayOneShot(currentSound);
}
function NextLevel(){
Application.LoadLevel("ValleyLevel");
}
function gameStart(){
attack=true;
}
When I test it in game mode the button does the rollover and on MouseUp the dragon breathes fire and moves toward the target object. When I do build and run the rollover works but the dragon just stops wherever he happens to be, no flames, no Lerp, no level open.
Answer by Bunny83 · Jan 29, 2011 at 03:19 AM
I can't belive that your setup work, even in "game mode".
var TargetScript : DragonGameIntro = gameObject.GetComponent(DragonGameIntro);
in this line you try to get a reference to the DragonGameInfo script. I guess, you didn't tell us the script names, your second script is the "DragonGameIntro" script and is attached to this dragon GameObject.
But you search for it on your GUITexture! I think you wanted do something like this:
var TargetScript : DragonGameIntro = Dragon.GetComponent(DragonGameIntro);
You don't use the Dragon-GameObject-reference at the moment, so maybe you implemented it later and forgot to change it in that line.
Thanks, I was sure it was something stupid. I too am puzzled how it worked in game mode. The fact that it worked had me overlooking the obvious.
Just another hint: If you create a windows build all Debug.Log will still logged but not in a console window like in the editor but to a text-file. The file is located in the data folder of your build and is called "output_log.txt". If there are errors like null-reference exceptions they will be logged into that file.
Your answer
Follow this Question
Related Questions
Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers
How can I stop the variable values reverting to its default values after being built? 1 Answer
Material/Shader issue 0 Answers
,Hololens Fail to resolve assembly WinRTLegacy 0 Answers
unity 5.6.2f1 64bit stuck at build 0 Answers