Пример #1
0
    void OnTriggerEnter2D(Collider2D objectHit)
    {
        if (objectHit.gameObject.CompareTag("Enemy"))
        {
            if (!gameObject.CompareTag("Projectile"))
            {
                objectHit.gameObject.GetComponent <HealthHandler>().TakeDamage(_weaponDamage);
                RemoveProjectile();
            }
        }
        else if (objectHit.gameObject.CompareTag("Player"))
        {
            if (!GameObject.Find("Shield").GetComponent <CircleCollider2D>().enabled)
            {
                objectHit.gameObject.GetComponent <HealthHandler>().TakeDamage(_weaponDamage);
                RemoveProjectile();
            }
        }
        else if (objectHit.gameObject.CompareTag("MainCamera"))
        {
            RemoveProjectile();
        }
        else if (objectHit.gameObject.CompareTag("Destructible") || objectHit.gameObject.CompareTag("Indestructable"))
        {
            if (objectHit.gameObject.CompareTag("Destructible"))
            {
                EnvironmentCollisionHandler _enviromentCollisionScript = objectHit.gameObject.GetComponent <EnvironmentCollisionHandler>();

                Vector3 _collisionVector = new Vector3(transform.position.x, transform.position.y + 0.3f, transform.position.z);
                _enviromentCollisionScript.RemoveTile(_collisionVector);

                _collisionVector.x += 0.1f;
                _enviromentCollisionScript.RemoveTile(_collisionVector);

                _collisionVector.x -= 0.2f;
                _enviromentCollisionScript.RemoveTile(_collisionVector);

                // Remove the projectile
                RemoveProjectile();
            }
            else
            {
                RemoveProjectile();
            }
        }
        else if (objectHit.gameObject.CompareTag("PlayerShield"))
        {
            objectHit.gameObject.GetComponent <ShieldHandler>().TakeDamage(_weaponDamage);
            RemoveProjectile();
        }
    }
Пример #2
0
    void LaserCannon()
    {
        if (_laserCannon.enabled == true)
        {
            //Determine laser start position (Position 0)
            shotStartPos  = transform.position;
            shotStartPos += new Vector2(0, _vertOffset);

            //Send a raycast upward
            hitInfo = Physics2D.Raycast(shotStartPos, transform.up);
            if (hitInfo)
            {
                Debug.Log(hitInfo.transform.name + " has been hit");
            }

            _laserCannon.SetPosition(0, shotStartPos);

            //Set laser end position (Position 1)
            if (hitInfo.transform.CompareTag("Enemy"))
            {
                _laserCannon.SetPosition(1, hitInfo.point);
                LaserCannonDamage();
            }
            else if (hitInfo.transform.CompareTag("Destructible") || hitInfo.transform.CompareTag("Indestructable"))
            {
                if (hitInfo.transform.CompareTag("Destructible"))
                {
                    EnvironmentCollisionHandler _enviromentCollisionScript = hitInfo.transform.gameObject.GetComponent <EnvironmentCollisionHandler>();

                    Vector3 _collisionVector = new Vector3(hitInfo.point.x, hitInfo.point.y + 0.3f, 0);
                    _enviromentCollisionScript.RemoveTile(_collisionVector);

                    _laserCannon.SetPosition(1, hitInfo.point);
                }
                else
                {
                    _laserCannon.SetPosition(1, hitInfo.point);
                }
            }
            else
            {
                _laserCannon.SetPosition(1, shotStartPos + new Vector2(0, 10));
            }
        }
    }