- Home /
Assets/Scripts/scriptEnemy.js(24,35): UCE0001: ';' expected. Insert a semicolon at the end.
Doing a Basic Unity Tutorial I came across the issue of the particle system not having a autodelete any more. I found a solution which is throwing up the error. Here is my code:
//Enemy Script
//Inspector Variables
var numberOfClicks : int = 2;
var respawnWaitTime : float = 2.0;
var shapeColour : Color[];
var explosion : Transform;
//Private Variables
private var storeClicks :int = 0;
//Called once
function Start(){
storeClicks = numberOfClicks;
}
//Called every frame
function Update(){
if(numberOfClicks <= 0){
if(explosion){
GameObject newexplosion = (GameObject) Instantiate(explosion,transform.position,transform.rotation);
Destroy(newexplosion,3);
}
var position = Vector3(Random.Range(-5,5),Random.Range(-5,5),12);
RespawnWaitTime();
transform.position = position;
numberOfClicks = storeClicks;
}
}
//Used to hide the game object for a set amount of time, and then unhide it.
function RespawnWaitTime(){
renderer.enabled = false;
RandomColour();
yield WaitForSeconds (respawnWaitTime);
renderer.enabled = true;
}
//Changes the colour of the material of the game object
function RandomColour(){
if(shapeColour.Length > 0){
var newColour = Random.Range(0,shapeColour.Length);
renderer.material.color = shapeColour[newColour];
}
}
I await your useful assistance.
Answer by Piflik · Aug 30, 2012 at 01:40 PM
That is a UnityScript code, but line 24 is C# (or looks like to me).
This:
GameObject newexplosion = (GameObject) Instantiate(explosion,transform.position,transform.rotation);
Should be:
var newexplosion : GameObject = Instantiate(explosion,transform.position,transform.rotation);
You've solved one problem but now there's another: Assets/Scripts/scriptEnemy.js(24,68): BCE0022: Cannot convert 'UnityEngine.Transform' to 'UnityEngine.GameObject'.
The declaration of 'explosion' has to be a gameobject ins$$anonymous$$d of a transform.
var explosion : GameObject;
Answer by Asad Chaudhry · Dec 10, 2012 at 09:31 PM
I know its a very late reply. Since i came across the same problem whilst working on the same tutorial . Here is how i solved it .
//Inspector Variables
var explosion : Transform ;
And then in the update function
var t : Transform = Instantiate(explosion,transform.position,transform.rotation);
var newExplosion : GameObject = t.transform.gameObject;
Destroy(newExplosion,2);
Answer by foresiite13 · Mar 05, 2013 at 10:52 PM
Hi guys I'm having a similar issue in myHealthControl.J's script. The affeced line: var healthBar: GameObject.HealthBarGUI.FindWithTag("HealthBarGUI");
Tht console says it is expecting ';'. Insert semicolon at the end. But I already have. Any help is greatly appreciated.
Also. On a side note, I am a Modeler and concept artist by nature so this coding system is foreign to me. I am willing to barter assets for scrip and script based components. Email me if interested: foresiite@gmail.com Thanks guys!