Пример #1
0
    public void AddHurtNum(string num, bool isHurt, bool isCrit)
    {
        HurtNum hurtNum = new HurtNum();

        hurtNum.txt    = num;
        hurtNum.isHurt = isHurt;
        hurtNum.isCrit = isCrit;
        queue.Enqueue(hurtNum);
    }
Пример #2
0
 void Update()
 {
     if (queue.Count > 0)
     {
         time += Time.deltaTime;
         if (time >= Const.HurtNumEmitterTime)
         {
             time = 0;
             HurtNum    hurtNum = (HurtNum)queue.Dequeue();
             GameObject obj     = Util.AddChild(hurtLabelObj, mTrans.parent);
             obj.transform.position = mTrans.position;
             obj.SetActive(true);
             UILabel label = obj.GetComponent <UILabel>();
             label.text = hurtNum.txt;
             if (hurtNum.isHurt)
             {
                 label.color = hurtColor;
             }
             else
             {
                 label.color = cureColor;
             }
             if (hurtNum.isCrit)
             {
                 label.fontSize = critSize;
             }
             else
             {
                 label.fontSize = normalSize;
             }
         }
     }
     else if (bDestroy)
     {
         Destroy(gameObject);
     }
 }
Пример #3
0
    //Hitted
    private void OnCollisionEnter2D(Collision2D other)
    {
        if (gamestage.stop == 1)
        {
            return;
        }

        if (other.gameObject.CompareTag("Plane"))
        {//碰撞的是Plane
            isJump       = false;
            isDoubleJump = false;
            if (EnvironmentType == 0)   //land jump down
            {
                if (Plane == null)
                {
                    Plane = other.gameObject;
                }
                if (Plane != other.gameObject)
                {
                    Plane.layer = LayerMask.NameToLayer("Default");
                    Plane.GetComponent <BoxCollider2D>().usedByEffector = true;
                    Plane = other.gameObject;
                }
            }
        }
        else if (other.gameObject.CompareTag("Monster"))
        {
            int HurtNum;
            if (EnvironmentType == 1 || EnvironmentType == 2)
            {
                HurtNum = (int)other.gameObject.GetComponent <Monster02_Controller>().Attacknum + Random.Range(0, (int)(other.gameObject.GetComponent <Monster02_Controller>().Attacknum * 0.5f));
            }
            else
            {
                HurtNum = (int)other.gameObject.GetComponent <Monster01_Controller>().Attacknum + Random.Range(0, (int)(other.gameObject.GetComponent <Monster01_Controller>().Attacknum * 0.5f));
            }
            //HurtNum = (HurtNum<PetDefence) ? 1 : (int)(HurtNum-PetDefence);
            HurtNum = Mathf.Max((int)(HurtNum - PetDefence * 0.1f), 1);
            HP     -= HurtNum;
            GameObject text = GameObject.Instantiate(HurtText);
            text.transform.parent   = GameObject.Find("Canvas").transform;
            text.transform.position = Camera.main.WorldToScreenPoint(transform.position) + new Vector3(80, 30, 0);
            text.GetComponent <TextMeshProUGUI>().text = HurtNum.ToString();
            //back
            float Dist           = Mathf.Abs(gameObject.transform.position.x - other.transform.position.x);
            float moveHorizontal = (gameObject.transform.position.x - other.transform.position.x) / Dist;
            rb.velocity = (new Vector2(1, 0) * moveHorizontal * 3);
            animator.SetBool("isDamaged", true);
            animator.SetBool("Damaging", false);
            gameObject.layer = LayerMask.NameToLayer("PlayerDamage");
            StartCoroutine("Damage");

            if (HurtedSound != null)
            {
                HurtedSound.Play();
            }
        }
        else if (other.gameObject.CompareTag("Boss"))
        {
            int HurtNum = (int)other.gameObject.GetComponent <Boss01_Controller>().Attacknum + Random.Range(0, (int)(other.gameObject.GetComponent <Boss01_Controller>().Attacknum * 0.5f));
            //HurtNum = (HurtNum<PetDefence) ? 1 : (int)(HurtNum-PetDefence);
            HurtNum = Mathf.Max((int)(HurtNum - PetDefence * 0.1f), 1);
            HP     -= HurtNum;
            GameObject text = GameObject.Instantiate(HurtText);
            text.transform.parent   = GameObject.Find("Canvas").transform;
            text.transform.position = Camera.main.WorldToScreenPoint(transform.position) + new Vector3(80, 30, 0);
            text.GetComponent <TextMeshProUGUI>().text = HurtNum.ToString();
            //back
            float Dist           = Mathf.Abs(gameObject.transform.position.x - other.transform.position.x);
            float moveHorizontal = (gameObject.transform.position.x - other.transform.position.x) / Dist;
            rb.velocity = (new Vector2(1, 0) * moveHorizontal * 3);
            animator.SetBool("isDamaged", true);
            animator.SetBool("Damaging", false);
            gameObject.layer = LayerMask.NameToLayer("PlayerDamage");
            StartCoroutine("Damage");

            if (HurtedSound != null)
            {
                HurtedSound.Play();
            }
        }
        //    else animator.SetInteger("Hitted", 0);
    }