Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class QuestionBlock : MonoBehaviour
  6. {
  7. public int timesToBeHit = 1;
  8. public GameObject prefabToAppear;
  9. public bool isSecret;
  10. private Animator anim;
  11. private Renderer render;
  12. private void Awake()
  13. {
  14. anim = GetComponentInParent<Animator>();
  15. //if it's a secret Question block
  16. if (isSecret)
  17. {
  18. render = GetComponentInParent<SpriteRenderer>();
  19. render.enabled = false;
  20. }
  21. }
  22.  
  23. public void OnCollisionEnter2D(Collision2D collision)
  24. {
  25. if (timesToBeHit > 0)
  26. {
  27. if(isSecret)
  28. {
  29. render.enabled = true;
  30. collision.gameObject.GetComponent<PlayerController>().isJumping = false; //Mario can't jump higher
  31. Instantiate(prefabToAppear, transform.parent.transform.position, Quaternion.identity); //instantiate other obj
  32. timesToBeHit--;
  33. anim.SetBool("IsSecret", true); //hit animation
  34. }
  35. else
  36. {
  37. collision.gameObject.GetComponent<PlayerController>().isJumping = false; //Mario can't jump higher
  38. Instantiate(prefabToAppear, transform.parent.transform.position, Quaternion.identity); //instantiate other obj
  39. timesToBeHit--;
  40. anim.SetTrigger("GotHit"); //hit animation
  41. }
  42.  
  43. }
  44.  
  45. if (timesToBeHit == 0)
  46. {
  47. anim.SetBool("EmptyBlock", true); //change sprite in animator
  48. }
  49. }
  50.  
  51. private bool IsPlayerBelow(GameObject go)
  52. {
  53. if ((go.transform.position.y + 1.4f < this.transform.position.y)) //if Mario is powered-up
  54. return true;
  55. if ((go.transform.position.y + 0.4f < this.transform.position.y) && !go.transform.GetComponent<PlayerController>().poweredUp)
  56. return true;
  57. return false;
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement