Ejemplo n.º 1
0
 public void OnTriggerEnter2D(Collider2D collider)
 {
     if (this.health > 0)
     {
         Orc1 orc  = collider.gameObject.GetComponent <Orc1> ();
         Orc2 orc2 = collider.gameObject.GetComponent <Orc2> ();
         if (orc != null)
         {
             if (!orc.isDead())
             {
                 if (collider == orc.bodyCollider)
                 {
                     this.removeHealth(1);
                     orc.attackRabit();
                 }
                 else if (collider == orc.headCollider)
                 {
                     orc.removeHealth(1);
                 }
             }
         }
         if (orc2 != null)
         {
             if (!orc2.isDead())
             {
                 if (collider == orc2.headCollider)
                 {
                     orc2.removeHealth(1);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
    float getDirection()
    {
        if (this.mode == Mode.Dead)
        {
            return(0);
        }
        if (this.mode == Mode.CarrotLeft)
        {
            return(-0.0000001f);
        }
        if (this.mode == Mode.CarrotRight)
        {
            return(0.0000001f);
        }

        if (this.mode == Mode.Dead)
        {
            return(0);
        }

        Vector3 my_pos    = this.transform.position;
        Vector3 rabit_pos = HeroRabit.current.transform.position;

        //start attack
        if (rabit_pos.x > Mathf.Min(pointA.x, pointB.x) &&
            rabit_pos.x < Mathf.Max(pointA.x, pointB.x))
        {
            mode    = Mode.Attack;
            current = this;
        }
        //end attack
        if (mode == Mode.Attack && !(rabit_pos.x > Mathf.Min(pointA.x, pointB.x) &&
                                     rabit_pos.x < Mathf.Max(pointA.x, pointB.x)))
        {
            mode = Mode.GoToA;
        }

        //if attack, move to the rabbit
        if (mode == Mode.Attack && !HeroRabit.current.isDead())
        {
            if (my_pos.x < rabit_pos.x)
            {
                return(1);
            }
            else
            {
                return(-1);
            }
        }

        //change mode if a or b reached
        if (this.mode == Mode.GoToB)
        {
            if (my_pos.x >= pointB.x)
            {
                this.mode = Mode.GoToA;
            }
        }
        else if (this.mode == Mode.GoToA)
        {
            if (my_pos.x <= pointA.x)
            {
                this.mode = Mode.GoToB;
            }
        }

        //get new direction
        if (this.mode == Mode.GoToB)
        {
            if (my_pos.x <= pointB.x)
            {
                return(1);
            }
            else
            {
                return(-1);
            }
        }
        else if (this.mode == Mode.GoToA)
        {
            if (my_pos.x <= pointA.x)
            {
                return(1);
            }
            else
            {
                return(-1);
            }
        }

        return(0);
    }