public void ProjectileBehavior() { if (target != null) { if (Vector3.Distance(transform.position, target.position) > minDistance) { direction = target.position - transform.position; _rb.AddForce((direction.normalized * moveSpeed * Time.fixedDeltaTime), ForceMode2D.Impulse); if (applyKnockback) { Vector2 dir = transform.position - transform.TransformVector(projLaunchPoint.position); _rb.AddForce((dir.normalized * _knockBackForce), ForceMode2D.Impulse); applyKnockback = false; _knockBackForce = -1f; } } else { if ((Time.time - timeLastFired) >= damageTickRate) { Vector3 projDir = target.position - transform.position; projDir = projDir.normalized; GameObject refr = Instantiate(projectileRefr, transform.TransformVector(projLaunchPoint.position), Quaternion.identity); ProjectileHandler pHandler = refr.GetComponent <ProjectileHandler>(); pHandler.damagePlayer = true; pHandler.SetLookDirection(projDir); pHandler.sr.sprite = _dataContainer.projectileSprite; pHandler.projectileVelocity = _dataContainer.projectileVelocity; pHandler.projectileDamage = _dataContainer.Damage; pHandler.projectileLifetime = _dataContainer.projectileLifetime; AudioManager._inst.PlaySFX(7); timeLastFired = Time.time; } } } }
public void FireWeapon(PlayerController pc) { if (FireMode == WeaponFiringType.full) { if (((Time.time - pc.timeLastFired) >= FireRate) && pc._firingWeapon && pc._inventory[pc._currInvIndex].ammoCount > 0) { if (projectile != null) { GameObject refr = Instantiate(projectile, pc.transform.GetChild(0).GetChild(0).position, Quaternion.identity); pc.timeLastFired = Time.time; pc._knockBackForce *= projectileKnockback_player; pc.applyKnockback = true; ProjectileHandler pHandler = refr.GetComponent <ProjectileHandler>(); AudioManager._inst.PlaySFX(sfxIndex); pHandler.damagePlayer = false; Vector2 dir = Input.mousePosition - Camera.main.WorldToScreenPoint(pc.transform.position); pHandler._collider.radius = projectileHitBoxRadius; pHandler.sr.sprite = projectileSprite; pHandler.SetLookDirection(dir.normalized); pHandler.projectileVelocity = projectileVelocity; pHandler.projectileDamage = projectileDamage; pHandler.projectileLifetime = projectileLifetime; pHandler.projectileKnockback = projectileKnockback_enemy; if (!pc.INFAMMO) { pc._inventory[pc._currInvIndex].ammoCount -= 1; pc._inventory[pc._currInvIndex].ammoCount = Mathf.Clamp(pc._inventory[pc._currInvIndex].ammoCount, 0, AmmoCap); pc._handChanged = true; } } } } else if (FireMode == WeaponFiringType.semi) { if (!pc._firingWeapon) { if (((Time.time - pc.timeLastFired) >= FireRate) && projectile != null && pc._inventory[pc._currInvIndex].ammoCount > 0) { GameObject refr = Instantiate(projectile, pc.transform.GetChild(0).GetChild(0).position, Quaternion.identity); pc.timeLastFired = Time.time; pc._knockBackForce *= projectileKnockback_player; pc.applyKnockback = true; ProjectileHandler pHandler = refr.GetComponent <ProjectileHandler>(); AudioManager._inst.PlaySFX(sfxIndex); Vector2 dir = Input.mousePosition - Camera.main.WorldToScreenPoint(pc.transform.position); pHandler._collider.radius = projectileHitBoxRadius; pHandler.sr.sprite = projectileSprite; pHandler.SetLookDirection(dir.normalized); pHandler.projectileVelocity = projectileVelocity; pHandler.projectileDamage = projectileDamage; pHandler.projectileLifetime = projectileLifetime; pHandler.projectileKnockback = projectileKnockback_enemy; if (weaponType == WeaponType.rocket) { pHandler.explode = true; } if (!pc.INFAMMO) { pc._inventory[pc._currInvIndex].ammoCount -= 1; pc._inventory[pc._currInvIndex].ammoCount = Mathf.Clamp(pc._inventory[pc._currInvIndex].ammoCount, 0, AmmoCap); pc._handChanged = true; } } } } }