- Home /
So my problem is that after I finished coding for my Maze I had gotten a simple error called "UCE0001: ';' expected. Insert a semicolon at the end." This here is my script and the error is on both Lines (9,15) and (10,15).
#pragma strict
@script RequireComponent(AudioSource)
public var collection_beep : AudioClip;
function Start ()
{
hasGun = false;
hasKey = false;
health = 0;
change GUITexture(false, "key");
change GUITexture(false, "gun");
}
static var GameObject=audio.Play();
function onControllerColliderHit(c : ControllerColliderHit)
{
if (c.gameObject.tag == "medpack" || AnimationCurve.GameObject.tag == "key" || AnimationCurve.GameObject.tag == "gun")
{
print("collided with "+AddComponentMenu.tag);
Destroy(AddComponentMenu.GameObject);
GameObject.audio.play();
if (AddComponentMenu.GameObject.tag == "medpack") health = 100;
if (AddComponentMenu.GameObject.tag == "key") hasKey = true;
if (AddComponentMenu.GameObject.tag == "gun") hasGun = true;
changeGUITexture(true, "gun");
}
}
{
Destroy(AddComponentMenu.GameObject);
GetComponent.().clip = collection_beep;
GetComponent.().Play();
}
function Update () {
}
Answer by Landern · Dec 14, 2016 at 04:43 PM
The script is EXTREMELY malformed and incorrect.
lets start at the top.
You have multiple variables in the Start function that don't exist and even if you declared them in the Start function off absolutely nothing to the entire script. If you want to use them within the script and other functions, you need to declare then outside of the functions unless the scope is completely local, which as we can see you're using the variables in the onControllerColliderHit function.... which isn't called in this script whatsoever so i guess it's being invoked from another script?
You have line 9 and 10 with the word change in front of GUITexture type, not sure whats going on there, should there be a change function within your script to take in a GUITexture as a parameter/argument?
On line 12 you're calling a function/method on the audio object called Play, but there isn't any definition for the audio object(unless it's a static class somewhere with a static Play method/function), but it's also called to declare a static variable in a class(your script) which is incorrect and will not function that way.
The onControllerColiiderHit function will fail all over the place due to the local variables declared in Start that are not scope to anything other then the Start function.
Line 19 seems very odd since you're calling GameObject.audio.play() without getting a component and doing it off the GameObject type explicitly. Line 23 seems to indicate there should be a method called changeGUITexture, but again, doesn't exist whatsoever.
Assuming there is a static class with a static variable called GameObject line 27 would work, but can't really be sure.
The GetComponet is malformed and incorrect syntax unless you meant to use a generic version of GetComponent with the type(script) in angle brackets, but the source of this question doesn't seem to indicate that is the case when the UA site doesn't render them they exist in the source of the question.
I think you should go through the unityscript/javascript tutorials and strengthen your coding skills and understanding of unity and the interactions.
Learning can be gained from: https://unity3d.com/learn
Your answer
![](https://koobas.hobune.stream/wayback/20220612102724im_/https://answers.unity.com/themes/thub/images/avi.jpg)