Ejemplo n.º 1
0
    public void NextPoint()
    {
        //Debug.Log("NEXT POINT");

        switch (mode)
        {
        case PatrolMode.Looping:
            waypointIndex = (waypointIndex + 1) % routelist.routes[routeSelect].Points.Length;
            ai.SetDestination(routelist.routes[routeSelect].GetGlobalPoint(waypointIndex));
            break;

        case PatrolMode.OneWay:

            if (waypointIndex < routelist.routes[routeSelect].Points.Length - 1)
            {
                waypointIndex = Mathf.Clamp(waypointIndex + 1, 0, routelist.routes[routeSelect].Points.Length);
                ai.SetDestination(routelist.routes[routeSelect].GetGlobalPoint(waypointIndex));
            }
            else
            {
                if (!hasEnded)
                {
                    statemachine.SetTrigger("Continue");
                    hasEnded = true;
                }
            }



            break;
        }
    }
Ejemplo n.º 2
0
    public override void OnStateUpdate(Animator animator, AnimatorStateInfo animatorStateInfo, int layerIndex)
    {
        float distance = Vector2.Distance(ai.transform.position, player.position);

        //Debug.Log("dist=" + distance);


        if (distance < 5)
        {
            ai.SetDestination(player.position);
        }
    }
Ejemplo n.º 3
0
    public void NextPoint()
    {
        Vector2 p = Random.insideUnitCircle.normalized;

        p = p * 2;
        p = (Vector2)ai.transform.position + p;


        NNInfo info = AstarPath.active.GetNearest(p);

        Vector3 closest = info.position;



        ai.SetDestination(closest);
    }
Ejemplo n.º 4
0
    public override void OnStateEnter(Animator animator, AnimatorStateInfo animatorStateInfo, int layerIndex)
    {
        hasEnded      = false;
        waypointIndex = 0;

        routelist = animator.GetComponent <RouteList>();
        ai        = animator.GetComponent <MyAI>();

        if (!alreadySubbed)
        {
            ai.OnFinishPath += NextPoint;
            alreadySubbed    = true;
        }

        statemachine = animator;
        ai.SetDestination(routelist.routes[routeSelect].GetGlobalPoint(waypointIndex));
        ai.stopMove = false;
    }
Ejemplo n.º 5
0
    public override void OnStateEnter(Animator animator, AnimatorStateInfo animatorStateInfo, int layerIndex)
    {
        ai = animator.GetComponent <MyAI>();
        ai.OnFinishPath = NextPoint;


        Vector2 p = Random.insideUnitCircle.normalized;

        p = p * 2;
        p = (Vector2)animator.transform.position + p;


        NNInfo info = AstarPath.active.GetNearest(p);

        Vector3 closest = info.position;



        ai.SetDestination(closest);
    }