Esempio n. 1
0
 void OnTriggerEnter2D(Collider2D collider)
 {
     print("trigger detected");
     if (collider.tag == "Player")
     {
         print("player trigger detected");
         FindObjectOfType <PlayerController>().gameObject.SetActive(false);
         LoseDetector.lost = true;
         AudioSource.PlayClipAtPoint(loseSound, transform.position);
         loseDetector.ShowLosePanel(LoseDetector.LoseReason.falling);
     }
     else
     {
         Destroy(collider.gameObject);
     }
 }
Esempio n. 2
0
 void DeactivatePlayer()
 {
     loseDetector.ShowLosePanel(LoseDetector.LoseReason.health);
 }
Esempio n. 3
0
    // Update is called once per frame
    void Update()
    {
        if (player == null)
        {
            player = FindObjectOfType <PlayerController>();
        }
        if (isFull)
        {
            persent = 100;
        }
        if (decreasing && !LoseDetector.lost)
        {
            decreasePercent();
        }
        if (color.Length != 4)
        {
            Debug.LogError("dont change Color array size, equale 4 !!!");
        }
        d = (109f / 100f) * persent;

        centerBar.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, d);
        topBar.transform.localPosition = emptyTopPos + new Vector2(0, d);
        if (persent <= 0)
        {
            if (decreasing)
            {
                AudioSource.PlayClipAtPoint(loseSound, player.transform.position);
            }
            persent           = 0;
            decreasing        = false;
            LoseDetector.lost = true;
            bar.SetActive(false);
            fullBar.SetActive(false);
            player.gameObject.SetActive(false);
            loseDetector.ShowLosePanel(LoseDetector.LoseReason.resource);
            if (color.Length > 0 && color.Length < 5)
            {
                SetColor(color[3]);
            }
        }
        else if (persent > 0 && persent < 100)
        {
            bar.SetActive(true);
            fullBar.SetActive(false);
            if (d < 25 && color.Length > 0 && color.Length < 5)
            {
                SetColor(color[3]);
            }
            else if (persent > 25 && persent < 50 && color.Length > 0 && color.Length < 5)
            {
                SetColor(color[2]);
            }
            else if (persent > 50 && persent < 75 && color.Length > 0 && color.Length < 5)
            {
                SetColor(color[1]);
            }
            else if (persent > 75 && color.Length > 0 && color.Length < 5)
            {
                SetColor(color[0]);
            }
        }
        else if (persent >= 100 && !isFull)
        {
            bar.SetActive(false);
            fullBar.SetActive(true);
            decreasing = false;
            persent    = 100;
            isFull     = true;
            AudioSource.PlayClipAtPoint(fullBarSound, player.transform.position);
            if (color.Length > 0 && color.Length < 5)
            {
                SetColor(color[0]);
            }
        }

        if (isFull && !displayedFullMessage) //allows only one full bar message to display at a time. If a bar is full when another message is showing, the message will show afterwards
        {
            if (!messager.displayingMessage)
            {
                messager.displayNewMessage(gameObject.name + " is now full!");
                Invoke("deleteFullBarMessage", 3f);
                displayedFullMessage       = true;
                winDetector.numBarsFilled += 1;
            }
        }
    }