public void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.GetComponentInChildren<MineralScript>() != null)
        {
            if (_ft == null)
            {
                _ft = Instantiate(FloatingText, Camera.main.WorldToScreenPoint(transform.position), new Quaternion(0, 0, 0, 0)) as FloatingTextScript;
                _ft.Immortal = false;
            }

            _ft.Number += (other.gameObject.GetComponentInChildren<MineralScript>().Value);

            _player.Money += other.gameObject.GetComponentInChildren<MineralScript>().Value;
            _audio.PlayOneShot(_audio.clip);
            Destroy(other.gameObject);
        }
    }
Exemple #2
0
    /*
     * void OnCollisionEnter2D(Collision2D collision)
     * {
     *  Debug.Log("Collision");
     *  if (collision.gameObject.GetComponent<Entity>().entityName.CompareTo(sourceEntity.entityName) != 0)
     *  {
     *      //if (collision.gameObject.tag.CompareTo("Enemy") == 0)
     *      //{
     *          Debug.Log("Hit Enemy");
     *          // Debug.Log(collision.gameObject.GetComponent<EnemyStats>().currentHP);
     *          collision.gameObject.GetComponent<Entity>().recieveDamage(damage);
     *
     *          GameObject text = Instantiate(textPrefab, transform.position, Quaternion.identity);
     *          text.GetComponent<FloatingTextScript>().setText("" + damage);
     *
     *     // }
     *
     *      Destroy(gameObject);
     *  }
     *  else
     *  {
     *      Debug.Log("Poggers hit self");
     *  }
     *
     * }
     */

    void OnTriggerEnter2D(Collider2D collision)
    {
        //CHECKS IF HITTING FRIENDLY
        if (collision.gameObject.tag.CompareTo(sourceEntity.gameObject.tag) == 0)
        {
        }
        //CHECKS IF HITTING ANYTHING BUT SELF
        else if (!GameObject.ReferenceEquals(collision.gameObject, sourceEntity.gameObject))
        {
            //CHECKS IF HIT WAS AN ENTITY
            if (collision.gameObject.GetComponent <Entity>() != null)
            {
                //CHECKS IF BULLET HASN'T COLLIDED WITH ANYTHING
                if (!registered)
                {
                    registered = true;
                    // Debug.Log("Hit Enemy");
                    Entity entityScript     = collision.gameObject.GetComponent <Entity>();
                    float  calculatedDamage = entityScript.CalculateDamage(damage, damageType);

                    if (entityScript.WillKill(calculatedDamage))
                    {
                        Debug.Log("Gain Exp");
                        entityScript.Die();
                        sourceEntity.GainExperience(200f);
                    }
                    else
                    {
                        entityScript.TakeDamage(calculatedDamage);
                    }



                    GameObject         text       = Instantiate(textPrefab, transform.position, Quaternion.identity);
                    FloatingTextScript textScript = text.GetComponent <FloatingTextScript>();
                    textScript.SetText("" + calculatedDamage);
                    textScript.SetColor(GetColor(damageType));
                    textScript.StartFloatText();
                }

                Destroy(gameObject);
            }
        }
    }
Exemple #3
0
 /// <summary>
 /// this function handles the amount of hits to the mole,
 /// which is accesible in the inspector for each mole
 /// </summary>
 public void GotHit()
 {
     getHit--;
     if (getHit >= 0)
     {
         collider.enabled = true;
     }
     else
     {
         parent.GetComponent <HoleRespawner>().hasMole = false;
         ScoreController.AddScore(score);
         GameObject pop = Instantiate(floatingText, transform.position, Quaternion.identity) as GameObject;
         // set the position of the floating text on the right position
         pop.transform.SetParent(UiController.instance.transform, false);
         pop.transform.position = Camera.main.WorldToScreenPoint(transform.position);
         FloatingTextScript popText = pop.GetComponent <FloatingTextScript>();
         Destroy(gameObject);
         popText.ShowFloatingText(score);
     }
 }