Exemplo n.º 1
0
    void FixedUpdate()
    {
        //while(true){
        //	yield return new WaitForEndOfFrame();

        var agent = this.GetComponent<NavMeshAgent>();
        if (this.vehicle.roubado) {
            roubado = true;
        } else {
            roubado = false;
        }

        //if(agent.hasPath && agent.remainingDistance < 2f){
        if(Vector3.Distance(this.transform.position, Game.Instance.market.position) < 3f && cart == null){
            //chegou no mercado
            //Debug.Log("chegou no mercado");
            var pos = this.transform.position + this.transform.forward;
            var rot = this.transform.rotation;
            cart = (Cart)Instantiate(Game.Instance.cartManager.cartPrefab, pos, rot);
            cart.transform.SetParent(Game.Instance.cartManager.transform);
            cart.AttachTo(this);
            cart.stuff.gameObject.SetActive(true);
            character.cart = true;
            //this.GetComponent<NavMeshAgent>().radius = 1.5f;
            //this.GetComponent<NavMeshAgent>().ResetPath();
            cart.GetComponent<NavMeshObstacle>().enabled = false;

        }else if(Vector3.Distance(this.transform.position, vehicle.transform.position) < 3f && cart != null){
            //chegou no carro de volta
            vehicle.ChangeToExit();
            cart.DetachFrom();
            cart.GetComponent<NavMeshObstacle>().enabled = true;
            cart.stuff.gameObject.SetActive(false);
            //Destroy(cart.gameObject);
            Destroy(this.gameObject);
        }
        //yield return new WaitForEndOfFrame();
        UpdateDestination();
        //yield return new WaitForEndOfFrame();
        //}

        //yield return new WaitForEndOfFrame();
        //}
    }