Design3-Unity.Scripting.2D.Space.Shooter problem

Hi all,
I am making one tutorial about Unity Scripting Space Shooter by Design3 and the code is the following:

var laser : GameObject;
var maxFireFreq : float;
private var lastShot : float;
var laserType : int ;
private var laserTimer : float ;

function Update () {
if (Input.GetButtonDown(“Fire1”) && (Time.time > lastShot + maxFireFreq) ) {
Fire();
}
laserTimer -= 1 * Time.deltaTime;
if (laserTimer < 0) {
laserType = 0;
}
}

function Fire() {
lastShot = Time.time;
if (laserType == 0) {
Instantiate(laser, transform.position, transform.rotation);
} else if (laserType == 1) {
Instantiate(laser, transform.position, Quaternion.Euler(Vector3(0,-20,0)));
yield WaitForSeconds (0.1);
Instantiate(laser, transform.position, transform.rotation);
yield WaitForSeconds (0.1);
Instantiate(laser, transform.position, Quaternion.Euler(Vector3(0,20,0)));
} else if (laserType == 2) {
Instantiate(laser, transform.position, Quaternion.Euler(Vector3(0,-30,0)));
yield WaitForSeconds (0.1);
Instantiate(laser, transform.position, Quaternion.Euler(Vector3(0,-15,0)));
yield WaitForSeconds (0.1);
Instantiate(laser, transform.position, transform.rotation);
yield WaitForSeconds (0.1);
Instantiate(laser, transform.position, Quaternion.Euler(Vector3(0,15,0)));
yield WaitForSeconds (0.1);
Instantiate(laser, transform.position, Quaternion.Euler(Vector3(0,30,0)));
}
function PowerUpLaser() {
laserType += 1;
laserType = Mathf.Clamp(laserType,0,2);
laserTimer = 3;
}

Now, I got the following errors:

1- Assets/Standard Assets/Scripts/FireScript1.js(40,11): BCE0044: expecting (, found ‘PowerUpLaser’.

2- Assets/Standard Assets/Scripts/FireScript1.js(40,25): UCE0001: ‘;’ expected. Insert a semicolon at the end.

3- Assets/Standard Assets/Scripts/FireScript1.js(41,19): BCE0044: expecting :, found ‘+=’.

For it, Could anybody help me with that problem?
Thanks in advance
Best Regards
Alejandro Castan

2 Answers

2

Hi, first of all I recommend to modify your question, formatting your code properly (it’s very hard to read!) - there is a specific button for code formatting, (the one with the binary code icon). However, it seems that you have not closed a bracket } for the function Fire() (if so, maybe also the other 2 errors will disappear).

By the way, have you learnt from that tutorial to use yield WaitForSeconds() in a function called from the Update()? Consider that’s really dangerous, since you wait for a certain amount of seconds in a function that still, however, called every frame: your application could have an uncontrolled behaviour, that way (even if the amout of time is very little, as in your case).

Hi BIG,
First of all, sorry to can badly the code, to be honest with you, I am learning to know the Unity Answers website and I will put the code like you advice me.
On the other hand, you are right, I added the bracket } at the end of the Fire () and the errors disappears.
Thank you so much for your help !
Regards
Alejandro