コード例 #1
0
    //This code is for showing a player's healthbar above his or her head.
    public bool showHealth(GameObject player, int prefix)
    {
        //RectTransform drawHealthHud; // for player heatlh above head
        MasterBody mb = player.GetComponent <MasterBody>();

        if (canvas != null)
        {
            if (showingPlayerHealth[prefix] == false)
            {
                showingPlayerHealth[prefix] = true;                                  //Sets it so this script knows the players health is already being shown.

                UIlifeBar[prefix] = Instantiate(this.UIhealthBar, canvas.transform); // add healthbar to canvas

                UIlifeBar[prefix].GetComponent <UILifeBar>().playerStats  = this;    // give player info to healthbar
                UIlifeBar[prefix].GetComponent <UILifeBar>().mb           = mb;      // masterbody gets assigned to lifebar
                UIlifeBar[prefix].GetComponent <UILifeBar>().playerPrefix = prefix;

                UIlifeBar[prefix].GetComponent <RectTransform>().anchorMin = Vector2.zero;
                UIlifeBar[prefix].GetComponent <RectTransform>().anchorMax = Vector2.zero;

                Vector3 pos = Camera.main.WorldToScreenPoint(player.transform.position + Vector3.up * 2); // position of player relative to screen
                pos.z = 0;

                UIlifeBar[prefix].GetComponent <RectTransform>().SetPositionAndRotation(pos, Quaternion.identity);
            }
            else
            {
                UIlifeBar[prefix].GetComponent <UILifeBar>().livespan = 0;
            }
        }
        return(true);
    }
コード例 #2
0
    private void OnTriggerEnter(Collider other)
    {
        // Checks whether this gameobject is a player, but isn't the player itself. Root is here the most upperparent.
        if (other.gameObject.tag == "Player" && !GameObject.Equals(other.transform.root.gameObject, parent) && !poisoned)
        {
            float      poisonDuration   = 2f;
            int        poisonCap        = 4;
            MasterBody masterBodyScript = gameObject.transform.root.gameObject.GetComponent <MasterBody>();

            poisoned = true;

            // This enemy will be assigned as the enemy so we can put this in DoPoisonDamage.
            GameObject enemy;

            // The enemy is the person who collides with trail.
            enemy = other.transform.root.gameObject;

            // Checks whether enemy already has the poison script.
            if (enemy.GetComponent <Poison>() == null)
            {
                // Gives poison script.
                poisonScript = enemy.AddComponent <Poison>();
            }

            poisonScript.parent = parent;
            // Our poisonEffecto in this script, gets the value of the poisonEffect from the Poison.cs.
            poisonScript.poisonEffect = poisonEffecto;
            poisonScript.StartCoroutine(poisonScript.DoPoisonDamage(poisonDuration, poisonCap, poisonDamage, enemy));
        }
    }
コード例 #3
0
    public void Explode()
    {
        Vector3 explodePos = explosive.transform.position;                // grab position of gameobject

        Collider[] colliders = Physics.OverlapSphere(explodePos, radius); // overlapsphere, any gameobject that has a collider, will be put in this array

        foreach (Collider hit in colliders)                               // want to get component of each collider
        {
            MasterBody player = hit.gameObject.GetComponent <MasterBody>();
            GameObject GO     = hit.transform.gameObject;

            // knockback thanks to the HammerAndSickle/MasterBody class
            if (player != null)
            {
                float distance = Vector3.Distance(transform.position, player.transform.position); // position between explosive and player

                // If the player is far from the explosion belt, it receives less damage and vice versa.
                float farDmg   = 2;
                float closeDmg = 5;

                if (distance == farDmg)
                {
                    player.TakeDamage(transform.gameObject, 2.0f, 10f, (GO.transform.position - explosive.transform.position).normalized + new Vector3(0, (-1) - (GO.transform.position - explosive.transform.position).normalized.y, 0));
                }

                if (distance == closeDmg)
                {
                    player.TakeDamage(transform.gameObject, 5.0f, 10f, (GO.transform.position - explosive.transform.position).normalized + new Vector3(0, (-1) - (GO.transform.position - explosive.transform.position).normalized.y, 0));
                }
            }
        }
        // Instantiate the particle effect upon hit. Code is from deathEffect particle (masterbody).
        particleObject = Instantiate(explodeEffect);
        particleObject.transform.position = transform.position;
    }
コード例 #4
0
    // when the player attacs
    public override void Fire()
    {
        // test if cooldown is over since last attack
        if (currentCooldown > Time.timeSinceLevelLoad)
        {
            return;
        }
        currentCooldown = Time.timeSinceLevelLoad + cooldown;

        //used for animation
        attack = true;

        //get every body in the attack area;
        foreach (Collider col in attackBox.collider)
        {
            //damaging the wall in the player confirm part of the game
            if (col.tag == "DestroyableWall")
            {
                getHit targetGetHit = col.GetComponent <getHit>();
                targetGetHit.health -= damage;
                targetGetHit.GetComponent <AudioSource>().Play();        //Plays the get hit sound effect.
            }

            GameObject GO = col.transform.root.gameObject;
            if (GO.tag == "Player")                          // if a player is hit
            {
                MasterBody EnemyMb = GO.GetComponent <MasterBody>();
                MasterBody mb      = gameObject.transform.root.GetComponent <MasterBody>();

                // get playerdata to later divide the coins
                playerStats.playerData enemy  = pS.players.Find(x => x.playerNr.Equals(EnemyMb.playerID)); // get the stat from the enemy
                playerStats.playerData player = pS.players.Find(x => x.playerNr.Equals(mb.playerID));      // get stats from self

                int enValue = (player.coins - enemy.coins) / 2;                                            // determine how many coins the enemy gets
                int plValue = (enemy.coins - player.coins) / 2;                                            // determine how many coins the player gets

                // add the determined amound coins to each player
                pS.addCoin(EnemyMb.name, enValue);
                pS.addCoin(mb.name, plValue);

                //give the enemy some damage and knockback
                EnemyMb.TakeDamage(gameObject.transform.root.gameObject, damage, knockBack, (GO.transform.position - transform.position).normalized + new Vector3(0, (-1) - (GO.transform.position - transform.position).normalized.y, 0));
            }
        }
        Shoot(); // play attacking sound
    }
コード例 #5
0
    Vector3 startScale;                         // the untransformed size of the box
    // Use this for initialization
    void Start()
    {
        startScale = transform.localScale;                  // store for reseting later
        cC         = GetComponentInParent <CharacterController>();
        mB         = GetComponentInParent <MasterBody>();
        rot        = topRot;                                // set start position lids
        lastY      = cC.velocity.y;

        // get the lids on the box
        flaps = new List <GameObject>();
        for (int i = 0; i < transform.childCount; i++)
        {
            if (transform.GetChild(i).name == "flapjoint")
            {
                flaps.Add(transform.GetChild(i).gameObject);
            }
        }
    }
コード例 #6
0
    //called when a player is killed. updates the amount of players alive and handles the end of the round
    public void updatePlayer(MasterBody deadPlayer)
    {
        playersAlive -= 1;
        temporaryRanking[playersAlive] = deadPlayer.playerID;
        Debug.Log("player" + temporaryRanking[playersAlive] + " Just finished in " + playersAlive + "th place");
        //If there are two people left, speed up the music
        if (playersAlive == 2)
        {
            goalPitch       = pitchTop;
            musicTransition = musicState.pitchUp;
        }
        else
        {
            goalPitch = pitchMiddle;
        }

        int winnerID = 0;

        // If there is only survivor left, loops through all the players and checks which is left alive. assigns that player as the winner.
        if (playersAlive == 1)
        {
            foreach (GameObject player in playersHolder)
            {
                if (player.GetComponent <MasterBody>().isAlive)
                {
                    winnerID = player.GetComponent <MasterBody>().playerID;
                    scoreCounter.updateScore(winnerID, "win");
                    temporaryRanking[0] = winnerID;
                    //Sets the color of the level transition:
                    transitionColor = playerColors[winnerID + 1];         //changes the color of the transitionscreen to match the color of the winning player. +1 because the first entry is
                    break;
                }
            }
            if (transitionGoing == false)
            {
                transitionGoing = true;

                GameObject tempGameObject = Instantiate(dropInObject, GameObject.FindGameObjectWithTag("Canvas").transform);
                tempGameObject.GetComponent <DropIn>().Drop(gameState.inbetweenRounds, winnerID + 1);
                goalPitch       = pitchMiddle;
                musicTransition = musicState.fadeOut;
            }
        }
    }
コード例 #7
0
    // Use this for initialization
    public void Init(GameObject[] p)
    {
        players             = new List <playerData>();
        showingPlayerHealth = new bool[5];       //This checks wether the life bar is already displayed
        UIlifeBar           = new GameObject[5]; //This keeps track of all uilifebars

        canvas = GameObject.FindGameObjectWithTag("Canvas");
        int i = 0;

        // p holds all players
        foreach (GameObject player in p)
        {
            MasterBody mb = player.GetComponent <MasterBody>();
            // add a entry in player data for each player
            playerData pd = new playerData(mb, Instantiate(playerDataUI, canvas.transform), mb.playerID);
            players.Add(pd);
            pd.coins = GameManager.instance.playerCoins[mb.playerID];
            i++;
        }
    }
コード例 #8
0
        public playerData(MasterBody mb, GameObject ui, int receivedPlayerNummer)
        {
            masterBody = mb;
            UI         = ui;
            UI.transform.Find("playerName").GetComponent <Text>().text = masterBody.name; // set name on info card on screen

            this.playerNr = receivedPlayerNummer;
            UI.GetComponent <RectTransform>().anchorMax = new Vector2(0.2f + (0.2f * playerNr), 0.2f);
            UI.GetComponent <RectTransform>().anchorMin = new Vector2(0.2f + (0.2f * playerNr), 0.2f);

            coinsText = UI.transform.Find("coinValue").GetComponent <Text>();
            healtBar  = UI.transform.Find("healthBar").transform.Find("health").GetComponent <RectTransform>();

            panel = UI.transform.Find("Panel").GetComponent <Image>();

            // set color of info panel based on player color
            panel.color = GameManager.instance.playerColors[playerNr + 1];
            panel.transform.Find("Panel background").GetComponent <Image>().color = new Color(GameManager.instance.playerColors[playerNr].r, GameManager.instance.playerColors[playerNr].g, GameManager.instance.playerColors[playerNr].b, cardTransp);
            coins = GameManager.instance.playerCoins[playerNr]; // update coins so that its equal to gameManager
            update();
        }
コード例 #9
0
 // Use this for initialization
 void Start()
 {
     player = gameObject.GetComponentInParent <MasterBody>();
 }