protected void SpawnShell() { if (Type == F3DWeaponController.WeaponType.Shotgun) { _weaponAudio.OnReload(AudioInfo); } if (Shell == null) { return; } // Pos var pos = ShellSocket.position; pos.z = -2; // Rotation var rot = ShellSocket.rotation * Quaternion.Euler(0, 0, Random.Range(-5, 5)); // Spawn var shell = F3DSpawner.Spawn(Shell, pos, rot, null); var shellRb = shell.GetComponent <Rigidbody2D>(); shellRb.AddForce((Vector2)ShellSocket.up * Random.Range(ShellForce.x, ShellForce.y), ForceMode2D.Impulse); shellRb.AddTorque(Random.Range(ShellTorque.x, ShellTorque.y), ForceMode2D.Force); // Despawn F3DSpawner.Despawn(shell, 1.5f); }
// Weapon drop on character killed public void Drop() { F3DGenericWeapon currentWeapon = GetCurrentWeapon(); var powerUpPrefab = currentWeapon.PowerUp; if (powerUpPrefab != null) { // Random Rotation var rot = currentWeapon.FXSocket.rotation * Quaternion.Euler(0, 0, Random.Range(-5, 5)); // Spawn var powerUp = F3DSpawner.Spawn(powerUpPrefab, currentWeapon.FXSocket.position, rot, null); // Flip var powerUpFlip = Mathf.Sign(currentWeapon.FXSocket.lossyScale.x); var curScale = powerUp.localScale; curScale.x *= powerUpFlip; powerUp.localScale = curScale; // Add random force / torque var powerUpRb = powerUp.GetComponent <Rigidbody2D>(); powerUpRb.AddForce((Vector2)currentWeapon.FXSocket.up * Random.Range(8, 12), ForceMode2D.Impulse); powerUpRb.AddTorque(Random.Range(-250, 250), ForceMode2D.Force); // remove gun after 2s F3DSpawner.Despawn(powerUp, 2f); } // Deactivate components currentWeapon.gameObject.SetActive(false); this.enabled = false; }
public static void SpawnHit(Transform hitPrefab, Vector2 contactPoint, Vector2 contactNormal, Transform parent, float lifeTime) { if (hitPrefab == null) { return; } var hit = F3DSpawner.Spawn(hitPrefab, contactPoint, Quaternion.LookRotation(Vector3.forward, contactNormal), parent); F3DSpawner.Despawn(hit, lifeTime); }
private void SpawnHit(Vector3 contactPoint, Vector3 contactNormal) { if (Hit == null) { return; } var normalOffset = contactNormal * Random.Range(HitNormalOffset.x, HitNormalOffset.y); var hit = F3DSpawner.Spawn(Hit, contactPoint + normalOffset, Quaternion.LookRotation(Vector3.forward, contactNormal), transform); F3DSpawner.Despawn(hit, 1f); }
private IEnumerator SpawnProjectileDelayed(Transform projectilePrefab, Vector2 position, Quaternion rotation) { if (!projectilePrefab) { yield break; } if (ProjectileDelay > 0) { yield return(new WaitForSeconds(ProjectileDelay)); } // Lifetime var lifeTime = Random.Range(ProjectileLifeTime.x, ProjectileLifeTime.y); // Spawn var projectile = F3DSpawner.Spawn(projectilePrefab, position, rotation, null); projectile.GetComponent <F3DGenericProjectile>().Source = transform.root.gameObject; // Set Weapon Type var projectileObject = projectile.GetComponent <F3DGenericProjectile>(); projectileObject.WeaponType = Type; projectileObject.DamageType = DamageType; projectileObject.DamageAmount = DamageAmount; // Set AudioInfo projectileObject.AudioInfo = AudioInfo; // Scale var scale = projectile.localScale * Random.Range(ProjectileBaseScale.x, ProjectileBaseScale.y); projectile.localScale = scale; var projRb = projectile.GetComponent <Rigidbody2D>(); var collider = projectile.GetComponent <Collider2D>(); // Ignore Self for (var j = 0; j < _colliders.Length; j++) { Physics2D.IgnoreCollision(collider, _colliders[j]); } // Launch var forceRandom = Random.Range(ProjectileForce.x, ProjectileForce.y); projRb.AddForce(projectile.right * forceRandom, ForceMode2D.Force); // Despawn on lifetime F3DSpawner.Despawn(projectile, lifeTime); }
protected void SpawnMuzzleFlash() { if (MuzzleFlash == null) { return; } // Direction _dir = Mathf.Sign(FXSocket.parent.lossyScale.x); // Pos var pos = FXSocket.position; pos += MuzzleFlashOffset.x * FXSocket.right * _dir; pos += MuzzleFlashOffset.y * FXSocket.up; pos.z = MuzzleFlashZ; // Rotation var rot = FXSocket.rotation; if (MuzzleFlashRandomFlip && Random.Range(-1f, 1f) < 0) { rot *= Quaternion.Euler(180, 0, 0); } if (_dir < 0) { rot *= Quaternion.Euler(0, 180, 0); } //var rotation = FXSocket.rotation *Quaternion.Euler(0, 0, Random.Range(MuzzleFlashRotation.x, MuzzleFlashRotation.y)); // Lifetime var lifeTime = Random.Range(MuzzleFlashLifeTime.x, MuzzleFlashLifeTime.y); // Spawn var muzzleFlash = F3DSpawner.Spawn(MuzzleFlash, pos, rot, FXSocket); // // Scale // var scale = muzzleFlash.localScale;//* Random.Range(MuzzleFlashBaseScale.x, MuzzleFlashBaseScale.y); // scale.x *= _dir; // scale.x += Random.Range(MuzzleFlashScaleX.x, MuzzleFlashScaleX.y); // scale.z = Random.Range(-1f, 1f) > 0 ? scale.z : -scale.z; // muzzleFlash.localScale = scale; _barrelEffects.Add(muzzleFlash); // Despawn F3DSpawner.Despawn(muzzleFlash, lifeTime); }
protected void SpawnBarrelSpark() { if (!BarrelSpark) { return; } var lifeTime = Random.Range(3, 3); // Pos var pos = FXSocket.position; pos.z = 0; // Rotation var rot = FXSocket.rotation; var barrelSpark = F3DSpawner.Spawn(BarrelSpark, pos, rot, null); _dir = Mathf.Sign(FXSocket.parent.lossyScale.x); var dirScale = barrelSpark.localScale; dirScale.x *= _dir; barrelSpark.localScale = dirScale; F3DSpawner.Despawn(barrelSpark, lifeTime); }
protected void SpawnSmoke() { if (!Smoke) { return; } var lifeTime = Random.Range(3, 3); // Pos var pos = FXSocket.position; pos.z = 0; // Rotation var rot = FXSocket.rotation; var smoke = F3DSpawner.Spawn(Smoke, pos, rot, null); var direction = Mathf.Sign(FXSocket.parent.lossyScale.x); var dirScale = smoke.localScale; dirScale.x *= direction; smoke.localScale = dirScale; _smokeEffects.Add(smoke); F3DSpawner.Despawn(smoke, lifeTime); }
protected void SpawnBeam(Transform projectilePrefab) { if (!projectilePrefab) { return; } // Pos var pos = FXSocket.position; pos.z = 0; // Rotation var rot = FXSocket.rotation; // Spawn var projectile = F3DSpawner.Spawn(projectilePrefab, pos, rot, FXSocket); // Set Weapon Type var projectileObject = projectile.GetComponent <F3DPulse>(); projectileObject.WeaponType = Type; projectileObject.AudioInfo = AudioInfo; }