public override void Start() { if (Camera == null) { throw new ArgumentException("Camera is not set"); } if (ShootSource == null) { throw new ArgumentException("ShootSource is not set"); } if (BulletPerSeconds <= 0) { throw new ArgumentException("BulletPerSeconds must be > 0"); } if (MaxAmmo <= 0) { throw new ArgumentException("MaxAmmo must be > 0"); } CurrentAmmo = MaxAmmo; soldier = Entity.Get <SoldierController>(); reloadSound = ShootSource.Get <AudioEmitterComponent>()["Reload"]; // Handle reload event soldier.Input.OnReload += (e) => { if (!IsReloading && CurrentAmmo != MaxAmmo) { Reload(); } }; BulletPerSeconds = 40; }
public override void Start() { if (ShootSource == null) { throw new ArgumentException("ShootSource not set"); } if (ShootTarget == null) { throw new ArgumentException("ShootTarget not set"); } if (Light == null) { throw new ArgumentException("Light not set"); } if (ShootTrail == null) { throw new ArgumentException("ShootTrail not set"); } if (ShootImpact == null) { throw new ArgumentException("ShootImpact not set"); } if (BulletHole == null) { throw new ArgumentException("BulletHole not set"); } var muzzleFlashEntity = ShootSource.FindChild("MuzzleFlash"); muzzleFlashParticles = muzzleFlashEntity?.Get <ParticleSystemComponent>()?.ParticleSystem; muzzleFlashParticles?.Stop(); laserEffect = ShootTrail.ParticleSystem; laserEffect.Stop(); laserImpact = ShootImpact.ParticleSystem; laserImpact.Stop(); BulletHole.ParticleSystem.Enabled = true; BulletHole.ParticleSystem.Stop(); Light.Enabled = false; AudioEmitterComponent shootEmitter = Entity.FindChild("ShootSource").Get <AudioEmitterComponent>(); AudioEmitterComponent shootTargetEmitter = ShootTarget.Get <AudioEmitterComponent>(); // Load different shoot sound effects shootSounds = new AudioEmitterSoundController[4]; for (int i = 0; i < shootSounds.Length; i++) { shootSounds[i] = shootEmitter["Shoot" + i]; } // Load different impact sound effects impactSounds = new AudioEmitterSoundController[4]; for (int i = 0; i < impactSounds.Length; i++) { impactSounds[i] = shootTargetEmitter["Impact" + i]; } SoldierWeapon weapon = Entity.Get <SoldierWeapon>(); weapon.OnShotFired += (soldierWeapon, result) => { Script.AddTask(async() => await FireWeapon(result)); }; }