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 BricksScript : MonoBehaviour
- {
- //A private variable that can be specified in the inspector
- //The amount of life of our brick
- public int life = 1;
- //Every time she comes into contact with something
- private void OnCollisionEnter(Collision collision)
- {
- //If it has a Ball tag
- if(collision.gameObject.tag == "Ball")
- {
- //we are removing one life
- life--;
- BrickColor();
- //If lives are equal to or less than 0
- if (life <= 0)
- {
- GameManager.instance.bricks.Remove(this.gameObject);
- GameManager.instance.UpdateUI();
- Destroy(gameObject); //destroy object
- }
- }
- }
- public void SetBrick(int life)
- {
- this.life = life;
- if (life <= 0) Destroy(gameObject);
- BrickColor();
- }
- void BrickColor()
- {
- Renderer renderer = GetComponent<Renderer>();
- Color[] colors = { Color.white, Color.blue, Color.red, Color.green };
- int colorIndex = Mathf.Clamp(life - 1, 0, colors.Length-1);
- renderer.material.color = colors[colorIndex];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement