View difference between Paste ID: HHmAqJqW and jmXi1L8w
SHOW: | | - or go back to the newest paste.
1
using System.Collections;
2
using System.Collections.Generic;
3
using UnityEngine;
4
5
public class BricksScript : MonoBehaviour
6
{
7-
    //Zmienna prywatna, którą można zmieniać w inspektorze
7+
    //A private variable that can be specified in the inspector
8-
    //Ilość życia naszej cegiełki
8+
    //The amount of life of our brick
9
    
10
    public int life = 1;
11
12
13-
    //Za każdym razem jak ona się zetknie z czymś
13+
    //Every time she comes into contact with something
14
    private void OnCollisionEnter(Collision collision)
15
    {
16-
        //Jeżeli ma to tag Ball
16+
        //If it has a Ball tag
17
        if(collision.gameObject.tag == "Ball")
18
        {
19-
            //usuawamy jedno życie
19+
            //we are removing one life
20
            life--;
21
            BrickColor();
22-
            //Jeżeli życia są równe lub mniejsze od 0
22+
            //If lives are equal to or less than 0
23
            if (life <= 0)
24
            {
25
                GameManager.instance.bricks.Remove(this.gameObject);
26
                GameManager.instance.UpdateUI();
27-
                Destroy(gameObject); //Zniszcz obiekt
27+
                Destroy(gameObject); //destroy object
28
            }
29
        }
30
    }
31
32
    public void SetBrick(int life)
33
    {
34
        this.life = life;
35
        if (life <= 0) Destroy(gameObject);
36
        BrickColor();
37
    }
38
39
    void BrickColor()
40
    { 
41
        Renderer renderer = GetComponent<Renderer>();
42
        Color[] colors = { Color.white, Color.blue, Color.red, Color.green };
43
        int colorIndex = Mathf.Clamp(life - 1, 0, colors.Length-1);
44
        renderer.material.color = colors[colorIndex];
45
    }
46
}
47