void DoCollisionDetection()
    {
        foreach (ColliderAABB wall in walls)
        {
            bool result = player.CheckOverlap(wall);

            //Trigger any Event after this...
        }
    }
    void DoCollisionDetection()
    {
        foreach (ColliderAABB powerup in powerups)
        {
            bool result = player.CheckOverlap(powerup);

            player.SetCollisionWith(result, powerup);

            powerup.SetCollisionWith(result, player);

            /*EVENTs
             * {
             *  //                print("collision!");
             *  //                 Destroy(powerup);
             *  //                Destroy(powerup.gameObject);
             *  powerup.GetComponent<MeshRenderer>().material.color = Random.ColorHSV(0, 1, 1, 1, 1, 1);
             *
             *  //event listeners,
             * }*/
        }
    }
    void CollisionDetectEnemy()
    {
        foreach (ColliderAABB Enemy in SceneControl.enemiesAABB)
        {
            bool resultEnemy = player.CheckOverlap(Enemy);

            if (resultEnemy)
            {
                // Player loses a life
                if (PlayerMovement.iFrameTimer <= 0 && PlayerMovement.speed > 0)
                {
                    Settings.lives--;
                    PlayerMovement.iFrameTimer = .5f / (PlayerMovement.speed / 20);
                    if (PlayerMovement.speed >= 20)
                    {
                        PlayerMovement.speed--;
                    }
                    AudioSource.PlayClipAtPoint(lifeDown1, soundPlayer.transform.position);
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (!playerRef.gameHasStarted)
        {
            if (chunks.Count > 0)
            {
                Destroy(chunks[0]);
                chunks.RemoveAt(0);
            }
            if (walls.Count > 0)
            {
                Destroy(walls[0]);
                walls.RemoveAt(0);
            }
            if (badguys.Count > 0)
            {
                Destroy(badguys[0]);
                badguys.RemoveAt(0);
            }
            if (powerups.Count > 0)
            {
                Destroy(powerups[0]);
                powerups.RemoveAt(0);
            }
            if (powerup2s.Count > 0)
            {
                Destroy(powerup2s[0]);
                powerup2s.RemoveAt(0);
            }
            if (powerup3s.Count > 0)
            {
                Destroy(powerup3s[0]);
                powerup3s.RemoveAt(0);
            }
            if (bullets.Count > 0)
            {
                Destroy(bullets[0]);
                bullets.RemoveAt(0);
            }
        }
        foreach (GameObject badGuy in badguys) //makes the bad guys run
        {
            if (badGuy == null)
            {
                continue;
            }
            badGuy.transform.position -= new Vector3(0, 0, .1f);
        }
        if (chunks.Count > 0)
        {
            if (chunks[0] == null)
            {
                return;
            }
            if (player.position.z - chunks[0].transform.position.z > 27)
            {
                Destroy(chunks[0]);
                chunks.RemoveAt(0);
            }
        }
        if (walls.Count > 0)
        {
            if (walls[0] == null)
            {
                return;
            }
            if (player.position.z - walls[0].transform.position.z > 27)
            {
                Destroy(walls[0]);
                walls.RemoveAt(0);
            }
        }
        if (badguys.Count > 0)
        {
            if (badguys[0] == null)
            {
                return;
            }
            if (player.position.z - badguys[0].transform.position.z > 27)
            {
                Destroy(badguys[0]);
                badguys.RemoveAt(0);
            }
        }
        if (powerups.Count > 0)
        {
            if (powerups[0] == null)
            {
                return;
            }
            if (player.position.z - powerups[0].transform.position.z > 27)
            {
                Destroy(powerups[0]);
                powerups.RemoveAt(0);
            }
        }
        if (powerup2s.Count > 0)
        {
            if (powerup2s[0] == null)
            {
                return;
            }
            if (player.position.z - powerup2s[0].transform.position.z > 27)
            {
                Destroy(powerup2s[0]);
                powerup2s.RemoveAt(0);
            }
        }
        if (powerup3s.Count > 0)
        {
            if (powerup3s[0] == null)
            {
                return;
            }
            if (player.position.z - powerup3s[0].transform.position.z > 27)
            {
                Destroy(powerup3s[0]);
                powerup3s.RemoveAt(0);
            }
        }
        if (bullets.Count > 0)
        {
            if (bullets[0] == null)
            {
                return;
            }
            if (bullets[0].transform.position.z - player.position.z > 40)
            {
                Destroy(bullets[0]);
                bullets.RemoveAt(0);
            }
        }
        while (chunks.Count < 15 && playerRef.gameHasStarted)
        {
            // spawn a new chunk
            Vector3 position = Vector3.zero;
            if (chunks.Count > 0)
            {
                position = chunks[chunks.Count - 1].transform.Find("Connector").position;
            }
            GameObject obj = Instantiate(prefabChunk, position, Quaternion.identity);
            chunks.Add(obj);
        }

        if (walls.Count > 0)
        {
            for (int i = 0; i < walls.Count; i++)
            {
                if (pBox.CheckOverlap(walls[i].GetComponent <ColliderAABB>()))
                {
                    if (playerRef.karma <= .3f)
                    {
                        playerRef.hp--;
                    }
                    else if (playerRef.karma >= .7f)
                    {
                        playerRef.hp -= 3;
                    }
                    else
                    {
                        playerRef.hp -= 2;
                    }
                    Destroy(walls[i]);
                    walls.RemoveAt(i);
                }
            }
        }

        if (badguys.Count > 0)
        {
            for (int i = 0; i < badguys.Count; i++)
            {
                if (pBox.CheckOverlap(badguys[i].GetComponent <ColliderAABB>()))
                {
                    if (playerRef.isAttacking)
                    {
                        playerRef.killed = true;
                        playerRef.karma -= .15f;
                    }
                    else if (playerRef.karma <= .3f && !playerRef.isAttacking)
                    {
                        playerRef.hp--;
                    }
                    else if (playerRef.karma >= .7f && !playerRef.isAttacking)
                    {
                        playerRef.hp -= 3;
                    }
                    else if (!playerRef.isAttacking)
                    {
                        playerRef.hp -= 2;
                    }
                    Destroy(badguys[i]);
                    badguys.RemoveAt(i);
                }
            }
        }
        if (powerups.Count > 0)
        {
            for (int i = 0; i < powerups.Count; i++)
            {
                if (pBox.CheckOverlap(powerups[i].GetComponent <ColliderAABB>()))
                {
                    playerRef.karma += .15f;
                    Destroy(powerups[i]);
                    powerups.RemoveAt(i);
                }
            }
        }
        if (powerup2s.Count > 0)
        {
            for (int i = 0; i < powerup2s.Count; i++)
            {
                if (pBox.CheckOverlap(powerup2s[i].GetComponent <ColliderAABB>()))
                {
                    if (playerRef.hp < 6)
                    {
                        playerRef.hp++;
                    }
                    Destroy(powerup2s[i]);
                    powerup2s.RemoveAt(i);
                }
            }
        }
        if (powerup3s.Count > 0)
        {
            for (int i = 0; i < powerup3s.Count; i++)
            {
                if (pBox.CheckOverlap(powerup3s[i].GetComponent <ColliderAABB>()))
                {
                    playerRef.karma -= .15f;
                    Destroy(powerup3s[i]);
                    powerup3s.RemoveAt(i);
                }
            }
        }
        if (bullets.Count > 0)
        {
            for (int i = 0; i < bullets.Count; i++)
            {
                float tempZ = bullets[i].transform.localPosition.z;
                tempZ += 1;
                for (int z = 0; z < walls.Count; z++)
                {
                    if (walls[z].GetComponent <ColliderAABB>().CheckOverlap(bullets[i].GetComponent <ColliderAABB>()))
                    {
                        Destroy(bullets[i]);
                        bullets.RemoveAt(i);
                        Destroy(walls[z]);
                        walls.RemoveAt(z);
                    }
                }
            }
        }
    }
Beispiel #5
0
    // Update is called once per frame
    void Update()
    {
        if (chunks.Count > 0)
        {
            if (player.position.z - chunks[0].transform.position.z > 14)
            {
                Destroy(chunks[0]);
                chunks.RemoveAt(0);
            }
        }

        while (chunks.Count < 5)
        {
            // spawn a new chunk
            Vector3 position = Vector3.zero;

            if (chunks.Count > 0)
            {
                position = chunks[chunks.Count - 1].transform.Find("Connector").position;
            }

            GameObject obj = Instantiate(prefabChunk, position, Quaternion.identity);
            chunks.Add(obj);
        }


        if (walls.Count > 0)
        {
            foreach (GameObject wall in walls)
            {
                if (pBox.CheckOverlap(wall.GetComponent <ColliderAABB>()))
                {
                    //print("Collision!");
                    if (wall != null)
                    {
                        //walls.Remove(wall);
                        wall.GetComponent <ColliderAABB>().isDead = true;
                    }
                }

                if (pickBox.CheckOverlap(wall.GetComponent <ColliderAABB>()))
                {
                    //print("Collision!");
                    if (wall != null)
                    {
                        //walls.Remove(wall);
                        PickAxeHit = true;
                        wall.GetComponent <ColliderAABB>().isDead = true;
                    }
                }
                if (shieldBox.CheckOverlap(wall.GetComponent <ColliderAABB>()))
                {
                    //print("Collision!");
                    if (wall != null)
                    {
                        //walls.Remove(wall);
                        powerup1 = true;
                        wall.GetComponent <ColliderAABB>().isDead = true;
                    }
                }
            }
        }
    }