Question by
RozzaStudios · Dec 20, 2015 at 03:05 PM ·
c#errorgun script
I get three errors, no idea why..
The errors I get: https://gyazo.com/0eacdb3c2e1cecc014d121aaebcc58c5 Sorry if I'm retarded! :)
using UnityEngine; using System.Collections;
public class Gun : MonoBehaviour {
public enum FireMode{Auto, Burst, Single};
public FireMode fireMode;
public Transform muzzle;
public Projectile projectile;
public float msBetweenShots = 100;
public float muzzleVelocity = 35;
public float burstCount;
public Transform shell;
public Transform shellEjection;
Muzzleflash muzzleflash;
float nextShotTime;
bool triggerReleasedSinceLastShot;
int shotsRemainingInBurst;
void Start(){
muzzleflash = GetComponent<Muzzleflash>();
shotsRemainingInBurst = burstCount;
}
void Shoot(){
if(fireMode == FireMode.Burst){
if(shotsRemainingInBurst == 0){
return;
}
shotsRemainingInBurst --;
}
else if(fireMode = FireMode.Single){
if(!triggerReleasedSinceLastShot){
return;
}
}
if (Time.time > nextShotTime) {
nextShotTime = Time.time + msBetweenShots / 1000;
Projectile newProjectile = Instantiate (projectile, muzzle.position, muzzle.rotation)as Projectile;
newProjectile.SetSpeed (muzzleVelocity);
Instantiate(shell, shellEjection.position, shellEjection.rotation);
muzzleflash.Activate();
}
}
public void OnTriggerHold(){
Shoot ();
triggerReleasedSinceLastShot = false;
}
public void OnTriggerRelease(){
triggerReleasedSinceLastShot = true;
shotsRemainingInBurst = burstCount;
}
}
Comment
Answer by ClaryKitty · Dec 21, 2015 at 09:18 AM
The first and last error are caused because you are trying to set an integer to the value of a float.
public float burstCount; and int shotsRemainingInBurst; need to both be either integers or floats, depending on your needs.
For the second error, it's simply caused by a missing '=' on the line else if(fireMode = FireMode.Single){}.