protected override void Start() { uic = FindObjectOfType <UIController>(); fallingSpeed = Random.Range(FALLING_SPEED_MIN, FALLING_SPEED_MAX) / FALLING_SPEED_INCR; state = FireballState.PreFalling; fallFrames = 0; eps = FALLING_SPEED_MAX / FALLING_SPEED_INCR; base.Start(); }
// Update is called once per frame void Update() { if (!uic.paused) { if (state == FireballState.PreFalling) { if (fallFrames >= preFallTime) { state = FireballState.Falling; } else { fallFrames++; } } if (state == FireballState.Fallen) { if (player) { player.TakeDamage(5); } Destroy(gameObject); return; } if (state == FireballState.Falling) { ball.SetActive(true); if (Mathf.Abs(ball.transform.position.y - transform.position.y) > eps) { Vector3 newPosition = ball.transform.position; newPosition.y -= fallingSpeed; ball.transform.position = newPosition; } else { ball.transform.position = transform.position; state = FireballState.Fallen; } } } }
public Fireball(Vector2 location) : base(location) { SoundManager.Instance.PlaySoundEffect(SpriteString.MarioFireball); ProjectileSprite = SpriteFactory.Instance.CreateSprite(ProjectileFactory.Instance.GetSpriteDictionary[GetType()]); ProjectileState = new FireballState(this); gravityManagement = new GravityManagement(this); if (Mario.MarioMovementState.MarioMovementType == MarioMovementType.RightRun || Mario.MarioMovementState.MarioMovementType == MarioMovementType.RightIdle || Mario.MarioMovementState.MarioMovementType == MarioMovementType.RightJump) { XVelocity = ProjectileUtil.projectileSpeed; } if (Mario.MarioMovementState is LeftRunningMarioMovementState || Mario.MarioMovementState is LeftIdleMarioMovementState || Mario.MarioMovementState is LeftJumpingMarioMovementState) { XVelocity = -ProjectileUtil.projectileSpeed; } }