r2foru
1
Im getting a Assets/Scrips/BoxLauncher.cs(17,18): error CS1525: Unexpected symbol `if’ error
here’s my script:
using System.Collections;
public class BoxLauncher : MonoBehaviour {
public GameObject[ ] boxPrefabs;
public float fireDelay = 3f;
float nextFire = 1f;
public float fireVelocity = 10f;
void FixedUpdate () {
nextFire -= Time.deltaTime
if(nextFire <= 0); {
//spawn a new box!
nextFire = fireDelay;
GameObject boxGo = (GameObject)Instantiate
( boxPrefabs[ Random.Range(0, boxPrefabs.Length)],
transform.position, transform.rotation);
boxGo.rigidbody2D.velocity = transform.rotation * new Vector2(0, fireVelocity);
}
}
}
Suddoha
2
Please use code tags.
You miss a semicolon behind
nextFire -= Time.deltaTime
Suddoha
4
Post the new script with code tags.
r2foru
5
using UnityEngine;
using System.Collections;
public class BoxLauncher : MonoBehaviour {
public GameObject[] boxPrefabs;
public float fireDelay = 3f;
float nextFire = 1f;
public float fireVelocity = 10f;
void FixedUpdate () {
nextFire -= Time.deltaTime
if (nextFire -= 0); {
//spawn a new box!
nextFire = fireDelay;
GameObject boxGo = (GameObject)Instantiate
( boxPrefabs[ Random.Range(0, boxPrefabs.Length)],
transform.position, transform.rotation);
boxGo.rigidbody2D.velocity = transform.rotation * new Vector2(0, fireVelocity);
}
}
}
r2foru
6
using UnityEngine;
using System.Collections;
public class BoxLauncher : MonoBehaviour {
public GameObject[] boxPrefabs;
public float fireDelay = 3f;
float nextFire = 1f;
public float fireVelocity = 10f;
void FixedUpdate () {
nextFire -= Time.deltaTime
if (nextFire -= 0); {
//spawn a new box!
nextFire = fireDelay;
GameObject boxGo = (GameObject)Instantiate
( boxPrefabs[ Random.Range(0, boxPrefabs.Length)],
transform.position, transform.rotation);
boxGo.rigidbody2D.velocity = transform.rotation * new Vector2(0, fireVelocity);
}
}
}
Suddoha
7
You still miss the semicolon in the line i qouted in my previous post.
1 Like
r2foru
8
now im getting this error: Assets/Scrips/BoxLauncher.cs(17,17): error CS0029: Cannot implicitly convert type float' to
bool’
using UnityEngine;
using System.Collections;
public class BoxLauncher : MonoBehaviour {
public GameObject[] boxPrefabs;
public float fireDelay = 3f;
float nextFire = 1f;
public float fireVelocity = 10f;
void FixedUpdate () {
nextFire -= Time.deltaTime;
if (nextFire -= 0); {
//spawn a new box!
nextFire = fireDelay;
GameObject boxGo = (GameObject)Instantiate
( boxPrefabs[ Random.Range(0, boxPrefabs.Length)],
transform.position, transform.rotation);
boxGo.GetComponent<Rigidbody2D>().velocity = transform.rotation * new Vector2(0, fireVelocity);
}
}
}
Suddoha
9
That’s because you’ve got a substraction in the parenthesis of the if, it needs to be an expression that evaluates to true or false.
This
if (nextFire -= 0);
should be
if (nextFire <= 0);