Exemplo n.º 1
0
 void Start()
 {
     orc = transform.parent.GetComponent <RedOrc>();
 }
Exemplo n.º 2
0
    float getDirection()
    {
        if (this.mode == Mode.Dead)
        {
            return(0);
        }

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

        //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;
        }
        //finish 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 rabit
        if (mode == Mode.Attack && !HeroRabit.current.isDead())
        {
            if (my_pos.x < rabit_pos.x)
            {
                return(1);
            }
            else
            {
                return(-1);
            }
        }

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

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