Exemplo n.º 1
0
 // Use this for initialization
 void Start()
 {
     livesKeeper = GameObject.Find ("Lives").GetComponent<LivesKeeper>();
     livesKeeper.Lives (health);
     float distanceFromCamera = transform.position.z - Camera.main.transform.position.z;
     Vector3 rightTop = Camera.main.ViewportToWorldPoint(new Vector3(1,1, distanceFromCamera));
     Vector3 rightBottom = Camera.main.ViewportToWorldPoint(new Vector3(1,0, distanceFromCamera));
     minplayerheightY = rightBottom.y + padding;
     maxplayerheightY = rightTop.y - padding;
 }
    // Use this for initialization
    void Start()
    {
        livesKeeper = GameObject.Find("Lives").GetComponent <LivesKeeper>();
        livesKeeper.Lives(health);
        float   distanceFromCamera = transform.position.z - Camera.main.transform.position.z;
        Vector3 rightTop           = Camera.main.ViewportToWorldPoint(new Vector3(1, 1, distanceFromCamera));
        Vector3 rightBottom        = Camera.main.ViewportToWorldPoint(new Vector3(1, 0, distanceFromCamera));

        minplayerheightY = rightBottom.y + padding;
        maxplayerheightY = rightTop.y - padding;
    }
    void OnTriggerEnter2D(Collider2D collider)
    {
        Projectile missile = collider.gameObject.GetComponent <Projectile>();

        if (missile)
        {
            health -= missile.GetDamage();
            missile.Hit();
            //added for health text
            livesKeeper.Lives(health);
            AudioSource.PlayClipAtPoint(hurtSound, transform.position);
            if (health <= 0)
            {
                Die();
            }
        }
    }