Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        for (int i = 0; i < arrowActivator.Length; i++)
        {
            //以后别在Update里面循环GetComponent,而且Get之后需要判空防止报错

            if (arrowActivator[i] == null)
            {
                return;
            }

            MachineTrigger arrowAct = arrowActivator[i].GetComponent <MachineTrigger>();
            if (arrowAct != null)
            {
                if (arrowAct.machineOn)
                {
                    if (checkRun == true)
                    {
                        gameObject.GetComponent <SpriteRenderer>().sprite = trapOn;
                        StartCoroutine(ShootArrow());
                        checkRun = false;
                    }
                }
                else
                {
                    gameObject.GetComponent <SpriteRenderer>().sprite = trapOff;
                    StopAllCoroutines();
                    checkRun = true;
                }
            }

            /*
             * if (arrowActivator[i].GetComponent<MachineTrigger> ().machineOn == true && checkRun == true) {
             *                  gameObject.GetComponent<SpriteRenderer> ().sprite = trapOn;
             *                  StartCoroutine (ShootArrow());
             *                  //lastRoutine = StartCoroutine (ShootArrow());
             *                  checkRun = false;
             *          } else if (arrowActivator[i].GetComponent<MachineTrigger> ().machineOn == false) {
             *                  gameObject.GetComponent<SpriteRenderer> ().sprite = trapOff;
             *                  StopAllCoroutines ();
             *                  checkRun = true;
             *          }*/
        }
    }
Ejemplo n.º 2
0
    public void TakeDamage()
    {
        Collider2D[] enemiesToDamage = Physics2D.OverlapCircleAll(attackPos.position, attackRange, enemies);

        for (int i = 0; i < enemiesToDamage.Length; i++)
        {
            if (enemiesToDamage[i].tag != "Bar")
            {
                CharacterHealth characterHealth = enemiesToDamage[i].GetComponent <CharacterHealth>();
                if (characterHealth != null)
                {
                    characterHealth.TakeDamage(damage);
                }

                if (enemiesToDamage[i].tag == "Hand")
                {
                }
            }
            else
            {
                MachineTrigger machineTrigger = enemiesToDamage[i].GetComponent <MachineTrigger>();
                if (machineTrigger != null)
                {
                    machineTrigger.StateChange();
                }
            }

            Vector2 pushDir = enemiesToDamage[i].transform.position - transform.position;
            pushDir = -pushDir.normalized;
            if (enemiesToDamage [i].tag == "Enemy")
            {
                //Debug.Log ("back");
                enemiesToDamage [i].GetComponent <Rigidbody2D> ().AddForce(-pushDir * hitForce * 100000000);
            }
        }

        //StartCoroutine(SetAttackRange());
    }
Ejemplo n.º 3
0
    public void TakeAttackRange()
    {
        charSprite.GetComponent <SpritesOutline>().outlineSize = 16;
        Collider2D[] enemiesToDamage = Physics2D.OverlapAreaAll(startPos.position, endPos.position, enemies);

        for (int i = 0; i < enemiesToDamage.Length; i++)
        {
            if (enemiesToDamage[i].tag == "Player" || enemiesToDamage[i].tag == "King" || enemiesToDamage[i].tag == "Boss" ||
                enemiesToDamage[i].tag == "Hand" || enemiesToDamage[i].tag == "Enemy")
            {
                CharacterHealth characterHealth = enemiesToDamage [i].GetComponent <CharacterHealth> ();
                if (characterHealth != null)
                {
                    characterHealth.TakeDamage(damage);
                }
            }
            else if (enemiesToDamage[i].tag == "Bar")
            {
                MachineTrigger machineTrigger = enemiesToDamage [i].GetComponent <MachineTrigger> ();
                if (machineTrigger != null)
                {
                    machineTrigger.StateChange();
                }
            }
            else if (enemiesToDamage[i].tag == "Breakable")
            {
                BreakableWall breakableWall = enemiesToDamage [i].GetComponent <BreakableWall> ();
                if (breakableWall != null)
                {
                    breakableWall.WallChange();
                }
            }
        }

        coolDownTime = startTime;
    }