You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.0 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Air : ActiveBlock
  5. {
  6. public float fallingAnimationTime = 1.0f;
  7. public float fallingDistance = 10.0f;
  8. public bool burnAfterReading = true;
  9. int DeleteCount = 2;
  10. public override int GetInitative()
  11. {
  12. return -1;
  13. }
  14. public override IEnumerator OnWalkedOnByPlayer(Character player, Vector3 moveDirection)
  15. {
  16. player.stuck = true;
  17. player.respawnNeeded = true;
  18. //Very hacky, but it solved a weird bug where falling off the left-hand-side of the track didn't kill you, it just got you stuck down there forever
  19. //You have to leave the camera's sight in order to die from falling
  20. yield return StartCoroutine(player.AnimateToPosition(transform.position + Vector3.down * fallingDistance,Character.Animation.Hit, fallingAnimationTime));
  21. //yield return StartCoroutine(LerpScale(player.transform, Vector3.zero, fallingAnimationTime));
  22. yield return StartCoroutine(player.AnimateToPosition(transform.position + Vector3.down * 100, Character.Animation.Hit, 0.01f));
  23. //player.gameObject.SetActive(false);
  24. Debug.Log("Set player scale to one");
  25. player.transform.localScale = Vector3.one;
  26. }
  27. public override IEnumerator OnRoundEnd(PlayerData[] allPlayers)
  28. {
  29. isFinished = true;
  30. if (burnAfterReading)
  31. {
  32. DeleteCount--;
  33. if (DeleteCount == 0)
  34. Destroy(gameObject);
  35. }
  36. yield break;
  37. }
  38. private IEnumerator LerpScale(Transform target, Vector3 endScale, float time)
  39. {
  40. Vector3 startScale = target.localScale;
  41. float elapsedTime = 0;
  42. while(elapsedTime < time)
  43. {
  44. target.localScale = Vector3.Slerp(startScale, endScale, (elapsedTime / time));
  45. yield return new WaitForEndOfFrame();
  46. elapsedTime += Time.deltaTime;
  47. }
  48. target.localScale = endScale;
  49. }
  50. }