Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyUp(KeyCode.Space))
        {
            if (state != ViusitorState.WAITING)
            {
                if (Random.value > 0.45f)
                {
                    return;
                }
            }

            chooseAndMove();
        }
        if (state == ViusitorState.MOVING)
        {
            float step = visitorSpeed * Time.deltaTime;
            transform.position = Vector2.MoveTowards(transform.position, target.transform.position, step);
            if (Vector3.Distance(transform.position, target.transform.position) < 0.001f)
            {
                //target.takeThePlace();
                state = ViusitorState.SITTING;
            }
        }
    }
Example #2
0
    //private void OnTriggerStay2D(Collider2D collision)
    //{
    //    if (state == ViusitorState.SITTING) return;
    //    Debug.Log("Trigger stay: " + this.name + " => " + collision.name + " " + collision.GetComponent<ChairLogic>().isFree());
    //    var chair = collision.GetComponent<ChairLogic>();
    //    if (chair == target)
    //    {
    //        if (chair.isFree())
    //        {
    //            chair.takeThePlace();
    //        }
    //        else
    //        {
    //            chooseAndMove();
    //        }
    //    }
    //}

    private void chooseAndMove()
    {
        if (target != null && state == ViusitorState.SITTING)
        {
            target.free();
        }
        target = chooseChair();
        state  = ViusitorState.MOVING;
    }