Пример #1
0
    // Update is called once per frame
    void Update()
    {
        RaycastHit hit;

        lineRenderer.SetPosition(0, new Vector3(0, 0, -11));

        if (Physics.Raycast(transform.position, -transform.forward, out hit))
        {
            if (hit.collider.gameObject.CompareTag("Player"))
            {
                if (gameController != null)
                {
                    gameController.GameOver();
                }
                if (survivalController != null)
                {
                    survivalController.GameOver();
                }
                Destroy(hit.collider.gameObject);
                Instantiate(deathEffect, hit.collider.gameObject.transform.position, hit.collider.gameObject.transform.rotation);
            }
        }
    }
Пример #2
0
    public void TakeDamage(float damage, GameObject other)
    {
        if (other.CompareTag("Shield"))
        {
            Instantiate(deathEffect, transform.position, transform.rotation);
            return;
        }
        if (other.CompareTag("Boundary") || other.CompareTag("Enemy") || other.CompareTag("EnemyBolt") || other.CompareTag("PowerUp"))
        {
            return;
        }

        if ((other.CompareTag("PlayerBolt") || other.CompareTag("LaserBeam")) && gameObject.CompareTag("EnemyBolt"))
        {
            return;
        }
        if (hitEffect != null)
        {
            Instantiate(hitEffect, transform.position, transform.rotation);
            if (!other.gameObject.CompareTag("LaserBeam"))
            {
                Destroy(other.gameObject);
            }
        }



        //Instantiate(hitEffect, other.transform.position, other.transform.rotation);

        if (!Immunity)
        {
            CurrentHealth -= damage;
            if (CurrentHealth <= 0)
            {
                Instantiate(deathEffect, transform.position, other.transform.rotation);
                if (gameController != null)
                {
                    gameController.SendMessage("Dead", transform.position, SendMessageOptions.DontRequireReceiver);
                    gameController.AddScore(scoreValue);
                }
                if (survivalController != null)
                {
                    survivalController.SendMessage("Dead", transform.position, SendMessageOptions.DontRequireReceiver);
                    survivalController.AddScore(scoreValue);
                }

                Destroy(gameObject);
            }
        }
        if (gameController != null)
        {
            gameController.SendMessage("Dead", transform.position, SendMessageOptions.DontRequireReceiver);
        }
        if (survivalController != null)
        {
            survivalController.SendMessage("Dead", transform.position, SendMessageOptions.DontRequireReceiver);
        }
        if (!other.gameObject.CompareTag("LaserBeam"))
        {
            Destroy(other.gameObject);
        }
        if (other.tag == "Player")
        {
            Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
            Destroy(other.gameObject);
            Destroy(gameObject);

            if (gameController != null)
            {
                //gameController.StartCoroutine(gameController.GameOver());

                gameController.GameOver();
            }
            if (survivalController != null)
            {
                //survivalController.StartCoroutine(survivalController.GameOver());
                survivalController.GameOver();
            }
        }
    }