Пример #1
0
    // Update is called once per frame
    void Update()
    {
        //Giving movement directions
        if (!agent.hasPath) //only counts the timer when not moving
        {
            timer += Time.deltaTime;
        }
        if (timer >= idleTime)
        {
            currentLocation.isOccupied = false;
            //loop until it reaches a not occupied spot
            if (currentTransformIndex == NPC_Manager.Instance.locations.Length - 1)
            {
                currentTransformIndex = -1; // -1 + 1 reset back to 0
            }
            while (NPC_Manager.Instance.locations[currentTransformIndex + 1].isOccupied == true)
            {
                if (currentTransformIndex == NPC_Manager.Instance.locations.Length - 1)
                {
                    currentTransformIndex = -1; // -1 + 1 reset back to 0
                }
                currentTransformIndex++;
            }
            currentLocation = NPC_Manager.Instance.locations[++currentTransformIndex];
            agent.SetDestination(currentLocation.transform.position);
            currentLocation.isOccupied = true;
            timer      = 0; //reset
            moveSwitch = true;
            moving     = true;
        }

        if (!agent.pathPending)
        {
            if (agent.remainingDistance <= agent.stoppingDistance)
            {
                if (!agent.hasPath || agent.velocity.sqrMagnitude == 0f)
                {
                    moving     = false;
                    moveSwitch = true;
                }
            }
        }
        //Setting the animation if walking
        if (moveSwitch)
        {
            if (moving)
            {
                anim.SetBool("Walking", true);
            }
            else
            {
                anim.SetBool("Walking", false);
            }
            moveSwitch = false;
        }
    }
Пример #2
0
 // Start is called before the first frame update
 void Start()
 {
     thisTransform          = GetComponent <Transform>();
     anim                   = GetComponent <Animator>();
     agent                  = GetComponent <NavMeshAgent>();
     currentTransformIndex  = Random.Range(0, NPC_Manager.Instance.locations.Length);
     currentLocation        = NPC_Manager.Instance.locations[currentTransformIndex];
     thisTransform.position = currentLocation.transform.position;
     Debug.Log(currentTransformIndex);
     currentLocation.isOccupied = true;
 }
Пример #3
0
 public void setCurrentLocation(HumanLocation location)
 {
     currentLocation = location;
 }