private IEnumerator makenew()
    {
        yield return(new WaitForSeconds(3f));

        HP1.SetActive(false);
        HP12.SetActive(false);
    }
    //受到攻擊後扣血
    override public void  TakeDamage(float amount)
    {
        //if(!alive){
        //    return;
        //}

        //if(currentHealth<=0){
        //     currentHealth=0;
        //     alive=false;
        // }


        base.TakeDamage(amount);
        HP1.SetActive(true);
        StartCoroutine(makenew());

        // if(currentHealth<=0||hitpoint<=0)
        //     {
        //         isdie=true;
        //         if(hitpoint>-8){
        //         CC.isTrigger = true;
        //         RB.useGravity=true;
        //         RB.isKinematic=false;


        //         }

        //     }
    }
Example #3
0
 private void Update()
 {
     Coins.text  = coins.ToString();
     Apples.text = apples.ToString();
     IsGrounded  = Physics2D.OverlapCircle(groundCheck.position, 0.5f, whatIsGround);        //0.485f
     if (IsGrounded && rb.velocity.y > -0.01f && rb.velocity.y < 0.01f)
     {
         jump = 0;
         anim.SetInteger("State", 0);
     }
     if (jump == 3)
     {
         jump = 1;
     }
     if (Input.GetAxis("Horizontal") < 0)
     {
         GetComponent <SpriteRenderer>().flipX       = true;
         Fight.GetComponent <BoxCollider2D>().offset = new Vector2(-0.06089044f, 0.02222253f);
         if (IsGrounded && rb.velocity.y > -0.01f && rb.velocity.y < 0.01f)
         {
             anim.SetInteger("State", 1);
         }
     }
     if (Input.GetAxis("Horizontal") > 0)
     {
         GetComponent <SpriteRenderer>().flipX       = false;
         Fight.GetComponent <BoxCollider2D>().offset = new Vector2(0.06089044f, 0.02222253f);
         if (IsGrounded && rb.velocity.y > -0.01f && rb.velocity.y < 0.01f)
         {
             anim.SetInteger("State", 1);
         }
     }
     if (rb.velocity.y > 0.01f)
     {
         anim.SetInteger("State", 2);
     }
     else if (rb.velocity.y < -0.01f)
     {
         anim.SetInteger("State", 3);
     }
     if (Input.GetKeyDown(KeyCode.UpArrow) && (IsGrounded || jump < 2))
     {
         jump += 1;
         if (jump == 1 || jump == 3)
         {
             anim.SetInteger("State", 5);
         }
         rb.velocity = Vector2.up * 12f;
     }
     if (Input.GetKeyDown(KeyCode.Z) && zPress == 0 && anim.GetCurrentAnimatorStateInfo(0).IsName("Attack_1") == false)
     {
         zPress = 1;
         anim.SetTrigger("Attack");
     }
     if (Input.GetKeyUp(KeyCode.Z))
     {
         zPress = 0;
     }
     if (Input.GetKeyDown(KeyCode.X) && xPress == 0 && anim.GetCurrentAnimatorStateInfo(0).IsName("Attack_2") == false)
     {
         xPress = 1;
         anim.SetTrigger("Attack2");
     }
     if (Input.GetKeyUp(KeyCode.X))
     {
         xPress = 0;
     }
     if (anim.GetCurrentAnimatorStateInfo(0).IsName("Attack_1") == true || anim.GetCurrentAnimatorStateInfo(0).IsName("Attack_2") == true)
     {
         eboshit = 1;
     }
     else
     {
         eboshit = 0;
     }
     if (IamHere == 1)
     {
         StartCoroutine(Bullet());
     }
     if (HPoint == 3)
     {
         HP1.GetComponent <Image>().color = new Vector4(255f, 255f, 255f, 255f);
         HP2.GetComponent <Image>().color = new Vector4(255f, 255f, 255f, 255f);
         HP3.GetComponent <Image>().color = new Vector4(255f, 255f, 255f, 255f);
     }
     if (HPoint == 2)
     {
         HP1.GetComponent <Image>().color = new Vector4(255f, 255f, 255f, 255f);
         HP2.GetComponent <Image>().color = new Vector4(255f, 255f, 255f, 255f);
         HP3.GetComponent <Image>().color = new Vector4(255f, 255f, 255f, 0f);
     }
     if (HPoint == 1)
     {
         HP1.GetComponent <Image>().color = new Vector4(255f, 255f, 255f, 255f);
         HP2.GetComponent <Image>().color = new Vector4(255f, 255f, 255f, 0f);
         HP3.GetComponent <Image>().color = new Vector4(255f, 255f, 255f, 0f);
     }
     if (HPoint == 0)
     {
         HP1.GetComponent <Image>().color = new Vector4(255f, 255f, 255f, 0f);
         HP2.GetComponent <Image>().color = new Vector4(255f, 255f, 255f, 0f);
         HP3.GetComponent <Image>().color = new Vector4(255f, 255f, 255f, 0f);
         transform.position = CheckPoint;
         HPoint             = 3;
     }
     if (plus15)
     {
         StartCoroutine(Plus1());
         plus15 = false;
     }
     if (plus25)
     {
         StartCoroutine(Plus2());
         plus25 = false;
     }
     if (plus50)
     {
         StartCoroutine(Plus3());
         plus50 = false;
     }
     if (transform.position.x < 0)
     {
         DownText.text = "Walk and jump on arrows. Fight on Z and X. Good luck!";
     }
     if (meetSodier)
     {
         DownText.text = "Horde Soldier: Go away, She-ra!";
     }
     else if (meetBug)
     {
         DownText.text = "Strange Creature: I came to find apples and won't go without one. If you have it, press right ctrl and give me it.";
     }
     else if (!meetBug && !meetSodier && transform.position.x >= 0)
     {
         DownText.text = "";
     }
 }