示例#1
0
    void Update()
    {
        Transform[] moveSpots = Script.GetComponent <Patrol>().moveSpots;
        int         nextSpot  = Script.GetComponent <Patrol>().nextSpot;

        FindVisableTargets();
        guard = GetComponent <Rigidbody>();

        //checks if target is in range
        if (transform.position == pos)
        {
            goBack = false;
        }
        if (!isTargetInRange && goBack == false)
        {
            Script.enabled = true;
            goBack         = false;
        }
        else if (!isTargetInRange && goBack == true && !(transform.position == pos))
        {
            //looks back to original point

            Script.enabled = false;


            //RotateToLastPoint(moveSpots, nextSpot);


            //StartCoroutine(Wait());
            transform.position = Vector3.MoveTowards(transform.position, moveSpots[nextSpot].position, 5 * Time.deltaTime);
            Quaternion targetRotation = Quaternion.LookRotation(moveSpots[nextSpot].transform.position - transform.position);
            rotation = targetRotation;
            Debug.Log(targetRotation);
            transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 4 * Time.deltaTime);

            //Debug.Log(goBack);
            pos = moveSpots[nextSpot].position;
            if (transform.position == pos)
            {
                goBack = false;
            }
            //Script.enabled = true;
        }
        else
        {
            //looks and moves towards player
            transform.position = Vector3.MoveTowards(transform.position, visibleTargets[0].position, 5 * Time.deltaTime);
            Quaternion targetRotation = Quaternion.LookRotation(visibleTargets[0].transform.position - transform.position);
            transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 5 * Time.deltaTime);
            Script.enabled     = false;

            goBack = true;
        }
        isTargetInRange = false;
    }
示例#2
0
    void OnTriggerStay2D(Collider2D coll)
    {
        string layer = LayerMask.LayerToName(coll.gameObject.layer);

        switch (layer)
        {
        case "Player":
            i_see_you();
            if (UI.S.currentSuspicion <= 0.0f)
            {
                Patrol enemy = this.transform.parent.GetComponent <Patrol>();
                enemy.enabled         = true;
                enemy.freak_out       = true;
                enemy.turn_cooldown   = 0.0f;
                enemy.movement_speed *= 3;
                enemy.GetComponent <Animator>().enabled = true;
                Destroy(this.gameObject);
            }
            break;

        default:
            break;
        }
    }