Esempio n. 1
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
    }
Esempio n. 2
0
 // Update is called once per frame
 void Update()
 {
     foreach (GameObject p in players)
     {
         if (p == null)
         {
             continue;
         }
         float dist = Vector3.Distance(p.transform.position, transform.position); // middle position from coin and player, CR: Jelmer
         if (dist < 4f)
         {
             p.GetComponent <MasterBody>().playSound(sndCoin);
             GameManager.instance.scoreCounter.updateScore(p.GetComponent <MasterBody>().playerID, "coin", 1);
             ps.addCoin(p.name, coinValue);
             Destroy(gameObject);
         }
     }
 }