private void LoadNextProjectile() { // Check because this is called from a coroutine if (this == null || this.View == null) { return; } // Already have a projectile if (this._currentProjectile != null) { return; } GameObject projectileGO = null; if (this._gameController.GameType == GameController.GameType_t.SINGLE_PLAYER) { projectileGO = PrefabLoader.Instance.InstantiateSynchronous(kProjectilePrefabPath, this.View.LaunchPosition); } else { projectileGO = MultiPlayerManager.Instance.InstantiatePrefab(kProjectilePrefabPath, this.View.LaunchPosition); } projectileGO.AssertNotNull("Projectile game object"); this._currentProjectile = projectileGO.GetComponent <Projectile>(); this._currentProjectile.AssertNotNull("Projectile component"); Rigidbody2D rigidbody2D = projectileGO.GetComponent <Rigidbody2D>(); rigidbody2D.AssertNotNull("RigidBody2D component"); rigidbody2D.gravityScale = 0.0f; }
private void LaunchCurrentProjectile(float normalizedStrength, float angle) { this._currentProjectile.AssertNotNull("Current projectile"); this._currentProjectile.MarkAsLaunched(); Rigidbody2D rigidbody2D = this._currentProjectile.gameObject.GetComponent <Rigidbody2D>(); rigidbody2D.AssertNotNull("RigidBody2D component"); rigidbody2D.gravityScale = 1.0f; float angleRad = angle * Mathf.PI / 180.0f; Vector2 force = new Vector2(Mathf.Cos(angleRad), Mathf.Sin(angleRad)) * Mathf.Lerp(kForceMultiplierMin, kForceMultiplierMax, normalizedStrength); rigidbody2D.AddForce(force); this._currentProjectile = null; CoroutineHelper.Instance.RunAfterDelay(kNextProjectileCooldownSeconds, this.LoadNextProjectile); }