public static Bullet GetBullet() { Bullet bullet = Instance.BulletPool.Retrieve(); bullet.Activate(); return(bullet); }
private bool FireBaseProjectile() { GameObject bullet = ObjectPooler.instance.SpawnFromPool(BulletTag, FireLocation.transform.position, Quaternion.identity); GameObject muzzleFlash = ObjectPooler.instance.SpawnFromPool("RRMuzzleFlash", FireLocation.transform.position, Quaternion.identity); muzzleFlash.transform.Rotate(transform.rotation.eulerAngles); //Check that bullet was loaded after pooler has been populated if (bullet != null) { Vector3 pelletRotation = transform.rotation.eulerAngles; bullet.transform.Rotate(pelletRotation); Bullet bulletScript = bullet.GetComponentInChildren <Bullet>(); if (bulletScript == null) { return(false); } bulletScript.Damage = Damage; bulletScript.KnockbackImpulse = KnockBackImpulse; bulletScript.KnockbackTime = KnockBackTime; bulletScript.StunTime = StunTime; bulletScript.Source = DamageSource.Enemy; bulletScript.Range = Range; bulletScript.Velocity = ProjectileSpeed; FireTimer = RateOfFire; bulletScript.Activate(); //audioSource.clip = FireSfx; //audioSource.Play(); return(true); } return(false); }
public void Fire(Vector3 pos, Vector3 direction, float speed) { Bullet b = GetBullet(); if (b) { AudioSource.PlayClipAtPoint(Pew[Random.Range(0, Pew.Count)], Vector3.Lerp(pos, GameObject.Find("Main Camera").transform.position, 0.9f)); b.Activate(); b.RB.position = pos; b.RB.velocity = direction * speed; } }
/// <summary> /// Fire out a bust of pellets in a random spread /// </summary> public override bool Fire() { // If we have ammo, are not reloading, and fire timer is zero, launch a spread of bullets if (AmmoInClip > 0 && !IsReloading && FireTimer < 0) { //Retrieve bullet from pooler GameObject bullet = ObjectPooler.instance.SpawnFromPool(BulletTag, FireLocation.transform.position, Quaternion.identity); //Check that bullet was loaded after pooler has been populated if (bullet != null) { //Remove bullet used to test status of pooler bullet.SetActive(false); IsReloading = false; AmmoInClip -= 1; //pellet rotation will be used for determining the spread of each bullet Vector3 pelletRotation; int damagePerPellet = Damage / NumPellets; //for the number of pellets we are firing, initalize a new bullet, update rotation and lunch it. for (int i = 0; i < NumPellets; i++) { pelletRotation = RotationPoint.rotation.eulerAngles; pelletRotation.z += Random.Range(-SpreadFactor, SpreadFactor); bullet = ObjectPooler.instance.SpawnFromPool(BulletTag, FireLocation.transform.position, Quaternion.Euler(pelletRotation)); //bullet.transform.Rotate(pelletRotation); Bullet bulletScript = bullet.GetComponent <Bullet>(); if (bulletScript == null) { bulletScript = bullet.GetComponentInChildren <Bullet>(); } bulletScript.Damage = damagePerPellet; bulletScript.KnockbackImpulse = KnockbackImpulse; bulletScript.KnockbackTime = KnockbackTime; bulletScript.StunTime = StunTime; bulletScript.Source = DamageSource.Spread; bulletScript.Range = Range; bulletScript.Velocity = BulletVeloc; bulletScript.Activate(); } FireTimer = RateOfFire; return(true); } return(false); } else { return(false); } }
public override bool Fire() { if (AmmoInClip > 0 && !IsReloading && FireTimer < 0) { //Gets the energyBurst objects from the pool (EnergyBurst functionally same as bullets) GameObject energyBurst = ObjectPooler.instance.SpawnFromPool(BulletTag, FireLocation.transform.position, Quaternion.identity); //muzzleFlash.transform.Rotate(RotationPoint.rotation.eulerAngles); IsReloading = false; AmmoInClip -= 1; Vector3 pelletRotation = RotationPoint.rotation.eulerAngles; pelletRotation.z += Random.Range(-SpreadFactor, SpreadFactor); energyBurst.transform.Rotate(pelletRotation); Bullet energyScript = energyBurst.GetComponentInChildren <Bullet>(); if (energyScript == null) { energyScript = energyBurst.GetComponentInChildren <Bullet>(); } energyScript.Damage = Damage; energyScript.KnockbackImpulse = KnockbackImpulse; energyScript.KnockbackTime = KnockbackTime; energyScript.StunTime = StunTime; energyScript.Source = BulletSource; energyScript.Range = Range; energyScript.Homing = BulletHoming; FireTimer = RateOfFire; energyScript.Velocity = BulletVeloc; energyScript.Activate(); if (audioSource.clip != FireSfx) { audioSource.clip = FireSfx; } if (!audioSource.isPlaying) { audioSource.Play(); } if (!LaserParticles.activeSelf) { LaserParticles.SetActive(true); } ShootBeamInDir(FireLocation.transform.position, FireLocation.transform.right); return(true); } else { return(false); } }
public void SpawnAngled() { for (int i = 0; i < data.amount; i++) { Bullet b = pool.GetBullet(data.type); b.Refresh(); Vector2 angle = -((Vector2)this.transform.position - Vector2.zero).normalized; angle = angle + (UnityEngine.Random.insideUnitCircle.normalized * 0.4f); angle = angle.normalized; b.Activate(this.transform.position, angle, data.delay); } inUse = false; }
/// <summary> /// Fire out a bust of pellets in a random spread /// </summary> public override bool Fire() { // If we have ammo, are not reloading, and fire timer is zero, launch a spread of bullets if (AmmoInClip > 0 && !IsReloading && FireTimer < 0) { //Retrieve bullet from pooler GameObject bullet = ObjectPooler.instance.SpawnFromPool(BulletTag, FireLocation.transform.position, Quaternion.identity); //GameObject muzzleFlash = ObjectPooler.instance.SpawnFromPool("MuzzleFlash", FireLocation.transform.position, Quaternion.identity); //muzzleFlash.transform.Rotate(RotationPoint.rotation.eulerAngles); //Check that bullet was loaded after pooler has been populated if (bullet != null) { //Remove bullet used to test status of pooler bullet.SetActive(false); IsReloading = false; AmmoInClip -= 1; //pellet rotation will be used for determining the spread of each bullet Vector3 pelletRotation; pelletRotation = RotationPoint.rotation.eulerAngles; pelletRotation.z += Random.Range(-SpreadFactor, SpreadFactor); bullet = ObjectPooler.instance.SpawnFromPool(BulletTag, FireLocation.transform.position, Quaternion.Euler(pelletRotation)); //bullet.transform.Rotate(pelletRotation); Bullet bulletScript = bullet.GetComponentInChildren <Bullet>(); bulletScript.Damage = Damage; bulletScript.KnockbackImpulse = KnockbackImpulse; bulletScript.KnockbackTime = KnockbackTime; bulletScript.StunTime = StunTime; bulletScript.Source = BulletSource; bulletScript.Homing = BulletHoming; bulletScript.Range = Range; bulletScript.Velocity = BulletVeloc; bulletScript.Activate(); FireTimer = RateOfFire; audioSource.clip = FireSfx; audioSource.Play(); return(true); } return(false); } else { return(false); } }
/// <summary> /// Fires a burst of 3 bullets, one by one, and then updates the HUD /// </summary> /// <returns></returns> private IEnumerator Shoot() { //Retrieve bullet from pooler GameObject bullet = ObjectPooler.instance.SpawnFromPool(BulletTag, FireLocation.transform.position, Quaternion.identity); GameObject muzzleFlash = ObjectPooler.instance.SpawnFromPool("VLMuzzleFlash", FireLocation.transform.position, Quaternion.identity); //muzzleFlash.transform.Rotate(RotationPoint.rotation.eulerAngles); //Check that bullet was loaded after pooler has been populated if (bullet != null) { IsReloading = false; AmmoInClip -= 1; Vector3 pelletRotation = RotationPoint.rotation.eulerAngles; pelletRotation.z += Random.Range(-SpreadFactor, SpreadFactor); bullet.transform.Rotate(pelletRotation); Bullet bulletScript = bullet.GetComponentInChildren <Bullet>(); bulletScript.Damage = Damage; bulletScript.KnockbackImpulse = KnockbackImpulse; bulletScript.KnockbackTime = KnockbackTime; bulletScript.StunTime = StunTime; bulletScript.Homing = BulletHoming; bulletScript.Source = BulletSource; bulletScript.Range = Range; bulletScript.Velocity = BulletVeloc; FireTimer = RateOfFire; bulletScript.Activate(); //TODO: Remove HUD update from Weapon class if (ControlledByPlayer) { HUDController.instance.UpdateAmmo(owner); // Update Weapon Ammo in HUD } audioSource.clip = FireSfx; audioSource.Play(); yield return(new WaitForSeconds(RateOfFire)); } // Reload weapon if out of bullets if (AmmoInClip == 0) { Reload(owner); } }
/// <summary> /// The fire function is used to launch a projectile from the tip of the automatic weapon /// </summary> public override bool Fire() { //if we have ammo, are not reloading, and the timer will let us fire another shot. Fire a bullet if (AmmoInClip > 0 && !IsReloading && FireTimer < 0) { //Retrieve bullet from pooler GameObject bullet = ObjectPooler.instance.SpawnFromPool(BulletTag, FireLocation.transform.position, Quaternion.identity); GameObject muzzleFlash = ObjectPooler.instance.SpawnFromPool("RRMuzzleFlash", FireLocation.transform.position, Quaternion.identity); //muzzleFlash.transform.Rotate(RotationPoint.rotation.eulerAngles); //Check that bullet was loaded after pooler has been populated if (bullet != null) { IsReloading = false; AmmoInClip -= 1; Vector3 pelletRotation = RotationPoint.rotation.eulerAngles; pelletRotation.z += Random.Range(-SpreadFactor, SpreadFactor); bullet.transform.Rotate(pelletRotation); Bullet bulletScript = bullet.GetComponentInChildren <Bullet>(); bulletScript.Damage = Damage; bulletScript.KnockbackImpulse = KnockbackImpulse; bulletScript.KnockbackTime = KnockbackTime; bulletScript.StunTime = StunTime; bulletScript.Source = BulletSource; bulletScript.Range = Range; bulletScript.Velocity = BulletVeloc; bulletScript.Homing = BulletHoming; FireTimer = RateOfFire; bulletScript.Activate(); audioSource.clip = FireSfx; audioSource.Play(); return(true); } return(false); } else { return(false); } }
/// <summary> /// Script that executes when the animation hits the shooting frame, which actually releases the bullet and plays the fire sound. /// </summary> void FireBullet() { Bullet b = GameManager.Instance.GetFreeBullet(); if (b != null) { ammoLeft--; bulletCounter.SetBulletCount(ammoLeft); b.Activate(mobile, shootPoint); if (onBullet && onBullet.isActiveAndEnabled) { var bMob = onBullet.GetComponent <Mobile>(); float rate = 0.33f * mobile.radius / bMob.radius; b.speed = Mathf.Abs(b.initialSpeed) * mobile.direction + onBullet.speed * rate; //onSomething.speed -= Mathf.Abs(speed) * mobile.direction; //bMob.refresh(); } b.SetColor(bulletColor); b.gameObject.SetActive(true); AudioManager.Instance().PlayFire(); } }
void Update() { if (Input.GetButton("Fire1") && cooldownClock < 0) { cameraShake.Shake(0.05f, 0.05f); sound.pitch = 1 + Random.Range(-0.1f, 0.1f); sound.Play(); // Vector2 direction = gunPivot.AimDirection; // Quaternion rotation = Quaternion.LookRotation(direction, Vector3.forward); // rotation.x = rotation.y = 0; // GameObject b = Instantiate(bulletPrefab, transform.position, rotation); // b.GetComponent<Bullet>().Activate(gunPivot.AimDirection, force, damage); // b.GetComponentInChildren<SpriteRenderer>().color = spriteRenderer.color; // rotation = Quaternion.LookRotation(direction, Vector3.up); // GameObject p1 = Instantiate(shotParticlesPrefab, transform.position, rotation); // ParticleSystem.MainModule m = p1.GetComponent<ParticleSystem>().main; // m.startColor = spriteRenderer.color; Bullet bullet = Instantiate(bulletPrefab, transform.position, Quaternion.identity).GetComponent <Bullet>(); bullet.Activate(gunPivot.AimDirection, parent); bullet.gameObject.tag = gameObject.tag; cooldownClock = cooldownTime; } cooldownClock -= Time.deltaTime; }
public void Shoot(float direction) { Bullet newBullet = Instantiate(bulletPF); newBullet.Activate(direction, bulletSpawnPoint.position, destroyer); }
public void Shoot(Bullet bullet) { bullet.Activate(gunEnd.position); }
public void Revert() { if (!active) { return; } if (states.Count < 3) { return; } GameState last = states[states.Count - 1]; //Time.timeScale = 1f / last.timeScale; //Time.fixedDeltaTime = 1f / last.timeScale * last.fixedDeltaTime; if (!pc.active && last.playerActive) { pc.Revive(); } player.transform.position = last.playerPos; playerBody.velocity = last.playerV; for (int i = 0; i < enemies.Count; i++) { enemies [i].transform.position = last.enemyPos[i]; enemyBody [i].velocity = last.enemyV[i]; Thing thing = enemies [i].GetComponent <Thing> (); if (thing.dead != last.enemyState [i]) { if (!last.enemyState [i]) { thing.Revive(); } else { thing.Die(); } } } for (int i = 0; i < last.bulletPos.Count; i++) { bullets [i].transform.position = last.bulletPos[i]; bulletBody [i].velocity = last.bulletV[i]; Bullet bul = bullets [i].GetComponent <Bullet> (); if (bul.active != last.bulletState [i]) { if (last.bulletState [i]) { bul.Activate(); } else { bul.Deactivate(); } } } if (last.bulletPos.Count < bullets.Count) { for (int i = last.bulletPos.Count; i < bullets.Count; i++) { bullets [i].GetComponent <Bullet> ().Deactivate(); } } for (int i = 0; i < obj.Count; i++) { obj [i].transform.position = last.objPos[i]; objBody [i].velocity = last.objV[i]; } states.RemoveAt(states.Count - 1); }
public void Watch() { if (states == null || watchIndex > states.Count - 1) { watching = false; return; } GameState curr = states [watchIndex]; player.transform.position = curr.playerPos; pc.active = curr.playerActive; playerBody.velocity = curr.playerV; for (int i = 0; i < enemies.Count; i++) { enemies [i].transform.position = curr.enemyPos[i]; enemyBody [i].velocity = curr.enemyV[i]; Thing thing = enemies [i].GetComponent <Thing> (); if (thing.dead != curr.enemyState [i]) { if (!curr.enemyState [i]) { thing.Revive(); } else { thing.Die(); } } } for (int i = 0; i < curr.bulletPos.Count; i++) { bullets [i].transform.position = curr.bulletPos[i]; bulletBody [i].velocity = curr.bulletV[i]; Bullet bul = bullets [i].GetComponent <Bullet> (); if (bul.active != curr.bulletState [i]) { if (curr.bulletState [i]) { bul.Activate(); } else { bul.Deactivate(); } } } if (curr.bulletPos.Count < bullets.Count) { for (int i = curr.bulletPos.Count; i < bullets.Count; i++) { bullets [i].GetComponent <Bullet> ().Deactivate(); } } for (int i = 0; i < obj.Count; i++) { obj [i].transform.position = curr.objPos[i]; objBody [i].velocity = curr.objV[i]; } watchIndex += 1; }
public static void Activar(Bullet bullet, Action <Bullet> _aviso) { aviso = _aviso; bullet.Activate(); }
//creates a bullet and initiales its parameters public void Fire(Transform t, BPAction a, float param, PrevRotWrapper prw) { //find the correct bulletTag that has info for this bullet var bt = bulletTags[a.bulletTagIndex - 1]; //Debug.Log("bt:"+bt.actions[0].type); //get the bullet Bullet temp = GetInstance(BulletManager.instance.bullets[bt.prefabIndex].bl, t, BulletManager.instance.bulletPrefab[bt.prefabIndex]); if (prw.prevRotationNull) { prw.prevRotationNull = false; prw.previousRotation = temp.transform.localRotation; } //set positions equal to its creator, which could be a Firetag or Bullet temp.transform.position = t.position; temp.transform.rotation = t.rotation; //set the abgle offset of new bullet float ang; if (a.useParam) { ang = param; } else { if (a.randomAngle) { ang = Random.Range(a.angle.x, a.angle.y); } else { ang = a.angle.x; } if (a.rankAngle) { ang += BulletManager.instance.rank * a.angle.z; } } //actually point the bullet in the right direction switch ((DirectionType)a.direction) { case (DirectionType.TargetPlayer): var originalRot = t.rotation; var dotHeading = Vector3.Dot(temp.transform.up, BulletManager.instance.player.position - temp.transform.position); int dir; if (dotHeading > 0) { dir = -1; } else { dir = 1; } var angleDif = Vector3.Angle(temp.transform.forward, BulletManager.instance.player.position - temp.transform.position); temp.transform.rotation = originalRot * Quaternion.AngleAxis((dir * angleDif) - ang, Vector3.right); break; case (DirectionType.Absolute): temp.transform.localRotation = Quaternion.Euler(-(ang - 270), 270, 0); break; case (DirectionType.Relative): temp.transform.localRotation = t.localRotation * Quaternion.AngleAxis(-ang, Vector3.right); break; case (DirectionType.Sequence): temp.transform.localRotation = prw.previousRotation * Quaternion.AngleAxis(-ang, Vector3.right); break; } //record this rotation for next Sequence Direction prw.previousRotation = temp.transform.localRotation; //set the speed, either from creator's speed data if (a.overwriteBulletSpeed) { float spd; if (a.randomSpeed) { spd = Random.Range(a.speed.x, a.speed.y); } else { spd = a.speed.x; } if (a.rankSpeed) { spd += BulletManager.instance.rank * a.speed.z; } if (a.useSequenceSpeed) { sequenceSpeed += spd; temp.speed = sequenceSpeed; } else { sequenceSpeed = 0f; temp.speed = spd; } } //or bulletTag data else { if (bt.randomSpeed) { temp.speed = Random.Range(bt.speed.x, bt.speed.y); } else { temp.speed = bt.speed.x; } if (bt.rankSpeed) { temp.speed += BulletManager.instance.rank * bt.speed.z; } } //set the bullets actions array, so it can perform actions later if it has any temp.actions = bt.actions; //pass random params to bullet, commented out because it seemed to be causing errors and I never used it anyway if (a.passParam) { temp.param = Random.Range(a.paramRange.x, a.paramRange.y); } //pass param that the creator received form another FireTag before creating this bullet(see readMe file) if (a.passPassedParam) { temp.param = param; } //give the bullet a reference to this script temp.master = this; //and activate it temp.Activate(); }
public static void ActivateBullet(Bullet bulletObj) { bulletObj.gameObject.SetActive(true); bulletObj.Activate(); }
void Shoot() { playerBullet.Activate(gunEnd.position); }