/// <summary> /// The method to launch extra balls. /// </summary> /// <param name="location">Transform giving the position, /// you can use an empty gameobject linked to launching object.</param> /// <param name="impulse">You can give the ball a "kick" when launching. Use null or Vector3.zero if not needed.</param> public void ExtraBall(Transform location, Vector3 impulse) { // Use a deactivated ball if possible. Pinball ball = RecycleBall(); // If not create a new ball from prefab. if (!ball) { ball = CreateNewBall(); } // If it was found activate it. else { ball.gameObject.SetActive(true); } // Update active ball counter and set ball location. AdjustActiveBallCounter(true); ball.transform.position = location.position; // If given a valid impulse vector apply it. if (impulse != null && !impulse.Equals(Vector3.zero)) { ball.AddImpulseForce(impulse); } }
private void Launch() { BallOnLauncher = false; SFXPlayer.Instance.Play(Sound.UkonKirves); _hitParticles.SetActive(true); PinballManager.Instance.SetPinballPhysicsEnabled(true); _pinball.AddImpulseForce(Vector3.forward * _launcherForce * _launcherForceMultiplier); _launchDone = true; _launcherForce = _minForceTime; // 10 seconds of Shoot Again PinballManager.Instance.ActivateShootAgain(10); // No longer need to show launch prompt. Viewscreen.EndLaunch(); }
/// <summary> /// Launches a given ball as an extra ball. /// </summary> public void LaunchExtraBall(Pinball ball) { if (_location == null) { Debug.LogError("No extra ball launch location set."); return; } ball.gameObject.SetActive(true); // Update active ball counter and set ball location. PinballManager.Instance.AdjustActiveBallCounter(true); ball.transform.position = _location.position; // If given a valid impulse vector apply it. if (_impulse != null && !_impulse.Equals(Vector3.zero)) { ball.AddImpulseForce(_impulse); } _ballsLeftToSpawn--; _mostRecentExtraBall = ball; }