private IEnumerator Dash(float chargeAmount) { float dashDuration = Mathf.Min(chargeAmount, 0.5f); AudioManager.instance.DashSound.Play(); // Set duration of particle system for each dash trail. dashEffect = Instantiate(dashEffectPrefab, transform.position, transform.rotation, transform); foreach (ParticleSystem ps in dashEffect.GetComponentsInChildren <ParticleSystem>()) { ps.Stop(); ParticleSystem.MainModule main = ps.main; main.duration = dashDuration; ps.Play(); } Vector2 direction = (Vector2)(Quaternion.AngleAxis(rb.rotation, Vector3.forward) * Vector3.right); float startTime = Time.time; while (Time.time - startTime <= dashDuration) { rb.velocity = direction * dashSpeed * (1.0f + chargeAmount); yield return(null); } foreach (ParticleSystem ps in dashEffect.GetComponentsInChildren <ParticleSystem>()) { ps.Stop(); } stateManager.CurrentStateHasFinished(); }
private void WallEnd() { if (stateManager.IsInState(State.LayTronWall)) { if (layWallCoroutine != null) { StopCoroutine(layWallCoroutine); } layWallCoroutine = null; PlaceCurrentWall(); stateManager.CurrentStateHasFinished(); } }
private void HandleGoalScored() { // When a goal is scored, we want to let go of the ball if (IsCarryingBall) { stateManager?.CurrentStateHasFinished(); } }
public void Shoot() { AudioManager.instance.ShootBallSound.Play(.5f); Ball ball = ballCarrier.Ball; if (ball != null) { Vector3 shotDirection = ball.transform.position - transform.position; Rigidbody2D ballRigidBody = ball.EnsureComponent <Rigidbody2D>(); ballRigidBody.velocity = shotDirection.normalized * shotSpeed; } StopShootBallCoroutines(); stateManager.CurrentStateHasFinished(); }
public void OnCollisionEnter2D(Collision2D collision) { GameObject other = collision.gameObject; Player player = other.GetComponent <Player>(); PlayerStateManager stateManager = other.GetComponent <PlayerStateManager>(); if (other.GetComponent <Ball>() != null) { DisableSelf(); return; } if ((player != null) && (stateManager != null) && (stateManager.currentState == State.Dash)) { DisableSelf(); other.EnsureComponent <Rigidbody2D>().velocity = Vector2.zero; stateManager.CurrentStateHasFinished(); } }
public void BeginPlayerMovement() { stateManager.CurrentStateHasFinished(); }