Exemplo n.º 1
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        if (!NetworkServer.active)
        {
            return;
        }

        AlienInvader hitAlien = collider.gameObject.GetComponent <AlienInvader>();

        if (hitAlien != null)
        {
            owner.score += hitAlien.score;
            NetworkServer.Destroy(hitAlien.gameObject);
            NetworkServer.Destroy(gameObject);
        }

        Shield hitShield = collider.gameObject.GetComponent <Shield>();

        if (hitShield != null)
        {
            NetworkServer.Destroy(hitShield.gameObject);
            NetworkServer.Destroy(gameObject);
        }
    }
Exemplo n.º 2
0
    void Update()
    {
        if (NetworkManager.singleton.numPlayers == 1)
        {
            waitfor.SetActive(true);
            return;
        }
        else if (NetworkManager.singleton.numPlayers == 2)
        {
            if (lastCount == 1)
            {
                waitfor.SetActive(false);
                lastCount = 2;
            }
        }



        if (gameOver)
        {
            return;
        }

        // update aliens
        if (Time.time >= nextTick)
        {
            nextTick = Time.time + tickLength;

            bool foundAlien = false;
            bool foundEdge  = false;
            foreach (GameObject alienObj in aliens)
            {
                if (alienObj == null)
                {
                    continue;
                }

                AlienInvader ai = alienObj.GetComponent <AlienInvader>();
                if (ai.score > 100)
                {
                    continue;
                }

                foundAlien = true;
                alienObj.transform.position += new Vector3(alienDir, 0, 0);
                alienObj.GetComponent <NetworkTransform>().SetDirtyBit(1);

                if (alienObj.transform.position.x > 10 || alienObj.transform.position.x < -10)
                {
                    foundEdge = true;
                }

                // can shoot if the lowest in my column
                bool  canShoot = true;
                float column   = ai.column;
                float row      = ai.row;
                foreach (GameObject other in aliens)
                {
                    if (other == null)
                    {
                        continue;
                    }

                    if (other.GetComponent <AlienInvader>().column == column)
                    {
                        if (other.GetComponent <AlienInvader>().row < row)
                        {
                            canShoot = false;
                            break;
                        }
                    }
                }
                ai.canShoot = canShoot;
            }

            if (!foundAlien)
            {
                CreateAliens();
                tickLength = 0.2f;
            }

            if (foundEdge)
            {
                alienDir   = -alienDir;
                tickLength = tickLength * 0.9f;                 // get faster

                foreach (GameObject alien in aliens)
                {
                    if (alien == null)
                    {
                        continue;
                    }

                    alien.transform.Translate(0, -0.8f, 0);
                    alien.GetComponent <NetworkTransform>().SetDirtyBit(1);
                }
            }
        }
    }