Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.AI;
- public class GoIntoShop : MonoBehaviour {
- public Transform Waypoint;
- public NavMeshAgent Agent;
- public Animator anim;
- public NPCSpawner nspawner;
- public Doors drs;
- public bool moveToDestination;
- public float distanceToStop;
- public void Start()
- {
- distanceToStop = 0.5f;
- Agent = GetComponent<NavMeshAgent>();
- Agent.updateRotation = true;
- Agent.autoBraking = true;
- moveToDestination = true;
- Agent.isStopped = false;
- nspawner = transform.parent.GetComponent<NPCSpawner>();
- drs = nspawner.drs;
- Agent.height = 0.5f;
- Agent.baseOffset = 0f;
- }
- void Update()
- {
- if (moveToDestination == true)
- {
- Agent.isStopped = false;
- Agent.updateRotation = true;
- float DistancetoWay = Vector3.Distance(transform.position, Waypoint.position);
- if (DistancetoWay < distanceToStop)
- {
- anim.SetFloat("Speed_f", 0f);
- moveToDestination = false;
- }
- } else
- {
- anim.SetFloat("Speed_f", 0f);
- Agent.isStopped = true;
- Agent.updateRotation = false;
- }
- float DistancetoWay2 = Vector3.Distance(transform.position, Waypoint.position);
- if (DistancetoWay2 > distanceToStop)
- {
- anim.SetFloat("Speed_f", 0.2f);
- moveToDestination = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement