Ejemplo n.º 1
0
 // Update is called once per frame
 void Update()
 {
     Debug.Log(health);
     switch (health)
     {
         case 5:
             heart1.gameObject.SetActive(true);
             heart2.gameObject.SetActive(true);
             heart3.gameObject.SetActive(true);
             heart4.gameObject.SetActive(true);
             heart5.gameObject.SetActive(true);
             break;
         case 4:
             heart1.gameObject.SetActive(true);
             heart2.gameObject.SetActive(true);
             heart3.gameObject.SetActive(true);
             heart4.gameObject.SetActive(true);
             heart5.gameObject.SetActive(false);
             break;
         case 3:
             heart1.gameObject.SetActive(true);
             heart2.gameObject.SetActive(true);
             heart3.gameObject.SetActive(true);
             heart4.gameObject.SetActive(false);
             heart5.gameObject.SetActive(false);
             break;
         case 2:
             heart1.gameObject.SetActive(true);
             heart2.gameObject.SetActive(true);
             heart3.gameObject.SetActive(false);
             heart4.gameObject.SetActive(false);
             heart5.gameObject.SetActive(false);
             break;
         case 1:
             heart1.gameObject.SetActive(true);
             heart2.gameObject.SetActive(false);
             heart3.gameObject.SetActive(false);
             heart4.gameObject.SetActive(false);
             heart5.gameObject.SetActive(false);
             break;
         case 0:
             SceneManager.LoadScene("GameOver");
             SituasiAwal.Normal();
             break;
     }
 }
Ejemplo n.º 2
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == "speedItem")
        {
            Destroy(other.gameObject);
            speed += 0.15f;
        }
        if (other.gameObject.tag == "finish")
        {
            if (ScrollBar.scroll == scrollLengkap)
            {
                SituasiAwal.Normal();
                SceneManager.LoadScene("MenuAwal");
            }
            else
            {
                Debug.Log("Gagal");
                SceneManager.LoadScene("GameOver");
            }
        }
        if (other.gameObject.tag == "scroll")
        {
            AudioSource.PlayClipAtPoint(ScrollSound, Camera.main.transform.position);
            other.gameObject.SetActive(false);
            int i = 1;
            ScrollBar.SaveScroll(i);
        }

        if (other.gameObject.tag == "errground")
        {
            Destroy(other.gameObject);
            varjump = 1;
        }

        if (other.gameObject.tag == "colmelayang")
        {
            trapMelayang   = GameObject.Find("SpikeMelayang").GetComponent <TrapMelayang>();
            trapMelayang.a = true;
        }
        if (other.gameObject.tag == "colspiketanah")
        {
            trapSpike   = GameObject.Find("Spike").GetComponent <TrapSpike>();
            trapSpike.a = true;
        }
        if (other.gameObject.tag == "colspikelangit")
        {
            trapSpikeJatuh   = GameObject.Find("SpikeJatuh").GetComponent <TrapSpikeJatuh>();
            trapSpikeJatuh.a = true;
        }
        if (other.gameObject.tag == "zerograf")
        {
            Destroy(other.gameObject);
            GetComponent <Rigidbody2D>().gravityScale = 0;
            varjump       = 2;
            speedmelayang = 0.12f;
            animation.SetBool("terbang", true);
            animation.SetBool("berlari", false);
        }
        if (other.gameObject.tag == "btslangit")
        {
            GetComponent <Rigidbody2D>().gravityScale = 1.5f;
            GetComponent <Rigidbody2D>().constraints  = RigidbodyConstraints2D.FreezeRotation;
            varjump = 1;
        }
    }