Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class QuestionBlock : MonoBehaviour
- {
- public int timesToBeHit = 1;
- public GameObject prefabToAppear;
- public bool isSecret;
- private Animator anim;
- private Renderer render;
- private void Awake()
- {
- anim = GetComponentInParent<Animator>();
- //if it's a secret Question block
- if (isSecret)
- {
- render = GetComponentInParent<SpriteRenderer>();
- render.enabled = false;
- }
- }
- public void OnCollisionEnter2D(Collision2D collision)
- {
- if (timesToBeHit > 0)
- {
- if(isSecret)
- {
- render.enabled = true;
- collision.gameObject.GetComponent<PlayerController>().isJumping = false; //Mario can't jump higher
- Instantiate(prefabToAppear, transform.parent.transform.position, Quaternion.identity); //instantiate other obj
- timesToBeHit--;
- anim.SetBool("IsSecret", true); //hit animation
- }
- else
- {
- collision.gameObject.GetComponent<PlayerController>().isJumping = false; //Mario can't jump higher
- Instantiate(prefabToAppear, transform.parent.transform.position, Quaternion.identity); //instantiate other obj
- timesToBeHit--;
- anim.SetTrigger("GotHit"); //hit animation
- }
- }
- if (timesToBeHit == 0)
- {
- anim.SetBool("EmptyBlock", true); //change sprite in animator
- }
- }
- private bool IsPlayerBelow(GameObject go)
- {
- if ((go.transform.position.y + 1.4f < this.transform.position.y)) //if Mario is powered-up
- return true;
- if ((go.transform.position.y + 0.4f < this.transform.position.y) && !go.transform.GetComponent<PlayerController>().poweredUp)
- return true;
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement