Пример #1
0
    void OnCollisionEnter(Collision coll)
    {
        GameObject otherGO = coll.gameObject;

        switch (otherGO.tag)
        {
        case "ProjectileHero":
            ProjectileHero p = otherGO.GetComponent <ProjectileHero>();

            if (bndCheck.offUp || bndCheck.offDown)
            {
                Destroy(otherGO);
                break;
            }

            health -= Main.GetWeaponDefinition(p.type).damageOnHit;
            ShowDamage();
            if (health <= 0)
            {
                if (!notifiedOfDestruction)
                {
                    Main.S.EnemyDefeated(this);
                }
                notifiedOfDestruction = true;
                Destroy(this.gameObject);
            }
            Destroy(otherGO);
            break;

        default:
            print("Enemy hit by non-projectileHero: " + otherGO.name);
            break;
        }
    }
Пример #2
0
    void TempFire()
    {
        GameObject projGO = Instantiate <GameObject>(projectilePrefab);

        projGO.transform.position = transform.position;
        Rigidbody rigidB = projGO.GetComponent <Rigidbody>();
        //  rigidB.velocity = Vector3. up * projectileSpeed;

        ProjectileHero proj = projGO.GetComponent <ProjectileHero>();

        proj.type = WeaponType.blaster;
        float tSpeed = Main.GetWeaponDefinition(proj.type).velocity;

        rigidB.velocity = Vector3.up * tSpeed;
    }
Пример #3
0
    public ProjectileHero MakeProjectile()
    {
        GameObject go = Instantiate <GameObject>(def.projectilePrefab);

        if (transform.parent.gameObject.tag == "Hero")
        {
            go.tag   = "ProjectileHero";
            go.layer = LayerMask.NameToLayer("ProjectileHero");
        }
        else
        {
            go.tag   = "ProjectileEnemy";
            go.layer = LayerMask.NameToLayer("ProjectileEnemy");
        }
        go.transform.position = collar.transform.position;
        go.transform.SetParent(PROJECTILE_ANCHOR, true);
        ProjectileHero p = go.GetComponent <ProjectileHero>();

        p.type       = type;
        lastShotTime = Time.time;
        return(p);
    }
Пример #4
0
    void OnCollisionEnter(Collision coll)
    {
        GameObject otherGO = coll.gameObject;

        switch (otherGO.tag)
        {
        case "ProjectileHero":
            ProjectileHero p = otherGO.GetComponent <ProjectileHero>();
            // If this Enemy is off screen, don't damage it.
            if (!bndCheck.isOnScreen)
            {
                Destroy(otherGO);
                break;
            }

            // Hurt this Enemy
            ShowDamage();
            // Get the damage amount from the Main WEAP_DICT.
            health -= Main.GetWeaponDefinition(p.type).damageOnHit;
            if (health <= 0)
            {
                // Tell the Main singleton that this ship was destroyed
                if (!notifiedOfDestruction)
                {
                    Main.S.shipDestroyed(this);
                }
                notifiedOfDestruction = true;
                // Destroy this Enemy
                Destroy(this.gameObject);
            }
            Destroy(otherGO);
            break;

        default:
            print("Enemy hit by non-ProjectileHero: " + otherGO.name);
            break;
        }
    }
Пример #5
0
    void OnCollisionEnter(Collision coll)
    {
        GameObject other = coll.gameObject;

        switch (other.tag)
        {
        case "ProjectileHero":
            ProjectileHero p = other.GetComponent <ProjectileHero>();
            // If this Enemy is off screen, don't damage it.
            if (!bndCheck.isOnScreen)
            {
                Destroy(other);
                break;
            }

            // Hurt this Enemy
            GameObject goHit  = coll.contacts[0].thisCollider.gameObject;
            Part       prtHit = FindPart(goHit);
            if (prtHit == null)      // If prtHit wasn't found…
            {
                goHit  = coll.contacts[0].otherCollider.gameObject;
                prtHit = FindPart(goHit);
            }

            // Check whether this part is still protected
            if (prtHit.protectedBy != null)
            {
                foreach (string s in prtHit.protectedBy)
                {
                    // If one of the protecting parts hasn't been destroyed...
                    if (!Destroyed(s))
                    {
                        // ... then don't damage this part yet
                        Destroy(other); // Destroy the ProjectileHero
                        return;         // return before damaging Enemy_4
                    }
                }
            }
            // It's not protected, so make it take damage
            // Get the damage amount from the Projectile.type and Main.W_DEFS
            prtHit.health -= Main.GetWeaponDefinition(p.type).damageOnHit;
            // Show damage on the part
            ShowLocalizedDamage(prtHit.mat);
            if (prtHit.health <= 0)
            {
                // Instead of destroying this enemy, disable the damaged part
                prtHit.go.SetActive(false);
            }

            // Check to see if the whole ship is destroyed
            bool allDestroyed = true;     // Assume it is destroyed

            foreach (Part prt in parts)
            {
                if (!Destroyed(prt))      // If a part still exists...
                {
                    allDestroyed = false; // ... change allDestroyed to false
                    break;                // & break out of the foreach loop
                }
            }
            if (allDestroyed)     // If it IS completely destroyed...
            {
                // ... tell the Main singleton that this ship was destroyed
                Main.S.shipDestroyed(this);
                // Destroy this Enemy
                Destroy(this.gameObject);
            }
            Destroy(other);     // Destroy the ProjectileHero
            break;
        }
    }
Пример #6
0
    void OnCollisionEnter(Collision coll)
    {
        GameObject other = coll.gameObject;

        switch (other.tag)
        {
        case "ProjectileHero":
            ProjectileHero p = other.GetComponent <ProjectileHero>();

            if (!bndCheck.isOnScreen)
            {
                Destroy(other);
                break;
            }

            GameObject goHit  = coll.contacts[0].thisCollider.gameObject;
            Part       prtHit = FindPart(goHit);

            if (prtHit == null)
            {
                goHit  = coll.contacts[0].otherCollider.gameObject;
                prtHit = FindPart(goHit);
            }

            if (prtHit == null)
            {
                print(goHit.name + " not found");
                break;
            }
            else
            {
                print("part found: " + prtHit.name);
            }

            if (prtHit.protectedBy != null)
            {
                foreach (string s in prtHit.protectedBy)
                {
                    if (!Destroyed(s))
                    {
                        Destroy(other);
                        return;
                    }
                }
            }

            prtHit.health -= Main.GetWeaponDefinition(p.type).damageOnHit;
            ShowLocalizedDamage(prtHit.mat);
            if (prtHit.health <= 0)
            {
                prtHit.go.SetActive(false);
            }

            bool allDestroyed = true;
            foreach (Part prt in parts)
            {
                if (!Destroyed(prt))
                {
                    print(prt.name);
                    allDestroyed = false;
                    break;
                }
            }
            print(allDestroyed);
            if (allDestroyed)
            {
                Main.S.EnemyDefeated(this);

                Destroy(this.gameObject);
            }
            Destroy(other);
            break;
        }
    }