public override void LateUpdateSui() { Vector3 position = m_sui.transform.position; if (position.y <= m_waterHeight) { m_sui.SetController(new SuiControllerSinking(m_sui)); WaterSplash splash = WaterSplashPool.Instance.Get(); if (splash != null) { splash.Splash(1.0f, Vector2.up, m_waterHeight, position.x); } AudioManager.GetInstance().SoundWaterSplash.Play(); } }
void Update() { Vector2 velocity = Velocity; if (IsOnWater && velocity.y > 0.0f) { Dude.SetBobyPartsKinematic(false); DudeAnimator.ClearClip(); m_isPLayingSwimmAnim = false; IsOnWater = false; IsInAir = true; m_waterWaver.Reset(); if (m_waterCircles != null) { m_waterCircles.Stop(); m_waterCircles = null; } } if (velocity.y > 0) { IsInAir = true; } Vector2 position = transform.position; float waterHeight; int waterStripIndex; Vector2 prevPosition = position; if (IsOnWater) { waterHeight = m_waterLevel.GetWaterHeight(transform.position.x, false); position = transform.position; position.y = waterHeight; position.y += m_waterWaver.GetValue(Time.deltaTime); position.x += velocity.x * Time.deltaTime; transform.position = position; } else { position += velocity * Time.deltaTime; } Bounds bounds = m_superheroArea.GetBounds(); float bounce_power = 0.3f; if (position.x < bounds.min.x) { position.x = bounds.min.x; velocity.x = -velocity.x * bounce_power; } if (position.x > bounds.max.x) { position.x = bounds.max.x; velocity.x = -velocity.x * bounce_power; } if (position.y > bounds.max.y) { position.y = bounds.max.y; velocity.y = 0.0f; } if (m_rescueAreaLeft.IsPointInside(position) || m_rescueAreaRight.IsPointInside(position)) { NotifyCollisionWithRescueArea(); } Bounds shoreLeftBounds = m_shoreLeftBounds.GetBounds(); if (position.x < shoreLeftBounds.max.x && position.y < shoreLeftBounds.max.y && velocity.y < 0 && prevPosition.y >= shoreLeftBounds.max.y) { position.y = shoreLeftBounds.max.y; velocity = Vector2.zero; if (IsInAir) { AudioManager.GetInstance().SoundLand.Play(); IsInAir = false; } } else if (position.x < shoreLeftBounds.max.x && position.y < shoreLeftBounds.max.y && velocity.x < 0 && prevPosition.y <= shoreLeftBounds.max.y) { position.x = shoreLeftBounds.max.x; velocity.x = -velocity.x * bounce_power; } Bounds shoreRightBounds = m_shoreRightBounds.GetBounds(); if (position.x > shoreRightBounds.min.x && position.y < shoreRightBounds.max.y && velocity.y < 0 && prevPosition.y >= shoreRightBounds.max.y) { position.y = shoreRightBounds.max.y; velocity = Vector2.zero; if (IsInAir) { AudioManager.GetInstance().SoundLand.Play(); IsInAir = false; } } else if (position.x > shoreRightBounds.min.x && position.y < shoreRightBounds.max.y && velocity.x > 0 && prevPosition.y <= shoreRightBounds.max.y) { position.x = shoreRightBounds.min.x; velocity.x = -velocity.x * bounce_power; } waterHeight = m_waterLevel.GetWaterHeight(transform.position.x, false); if (position.y <= waterHeight && !IsOnWater && velocity.y <= 0.0f) { IsOnWater = true; IsInAir = false; SpawWaterCircles(position); // TODO, water circles // m_water.Impulse(waterStripIndex, Mathf.Min(3.0f, Velocity.magnitude), position.x); velocity.y = 0.0f; velocity.x = 0.0f; WaterSplash splash = WaterSplashPool.Instance.Get(); if (splash != null) { splash.Splash(1.0f, Vector2.up, waterHeight, position.x); } AudioManager.GetInstance().SoundWaterSplash.Play(); } if (IsOnWater && velocity.x != 0.0f) { if (!AudioManager.GetInstance().SoundSwim.IsPlaying()) { AudioManager.GetInstance().SoundSwim.Play(); } m_nextWaterCircleWhenSwimming -= Time.deltaTime; if (m_nextWaterCircleWhenSwimming <= 0.0f) { m_nextWaterCircleWhenSwimming = Random.Range(0.2f, 0.4f); SpawWaterCircles(position); } } else { if (AudioManager.GetInstance().SoundSwim.IsPlaying()) { AudioManager.GetInstance().SoundSwim.Stop(); } } if (IsOnWater && !m_isPLayingSwimmAnim) { Dude.SetBobyPartsKinematic(true); if (Dude.IsConnected(BodyPartType.HandLeft)) { Dude.SetBobyPartKinematic(BodyPartType.HandLeft, false); } if (Dude.IsConnected(BodyPartType.HandRight)) { Dude.SetBobyPartKinematic(BodyPartType.HandRight, false); } DudeAnimator.Swim(); m_isPLayingSwimmAnim = true; m_isPLayingJumpAnim = false; } if (!IsOnWater && !m_isPLayingJumpAnim) { Dude.SetBobyPartsKinematic(true); if (Dude.IsConnected(BodyPartType.HandLeft)) { Dude.SetBobyPartKinematic(BodyPartType.HandLeft, false); } if (Dude.IsConnected(BodyPartType.HandRight)) { Dude.SetBobyPartKinematic(BodyPartType.HandRight, false); } DudeAnimator.Jump(); m_isPLayingJumpAnim = true; } Velocity = velocity; transform.position = new Vector3(position.x, position.y, -0.3f); }