Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class NPCMovement : MonoBehaviour
- {
- public Transform WayPointsHolder;
- [Header("No modificar")] public List<Transform> ExistWayPoints = new List<Transform>();
- [Header("No modificar")] public int CurrentWayPoint;
- Vector3 refMove;
- public float SmoothMove = 100f;
- [Header("Estos seran los movimientos")]public int Movimientos;
- [Header("No modificar")]public int CurrentMove;
- private void Start()
- {
- for (int i = 0; i < WayPointsHolder.childCount; i++)
- {
- ExistWayPoints.Add (WayPointsHolder.GetChild(i).transform);
- }
- }
- private void Update()
- {
- CurrentWayPoint = Mathf.Clamp (CurrentWayPoint, 0, ExistWayPoints.Count - 1);
- if (WayPointsHolder == null)
- {
- print ("<color=yellow> Por favor inserta el manager de los waypoints</color>");
- }
- else
- {
- float distance = Vector3.Distance (this.transform.position, ExistWayPoints[CurrentWayPoint].position);
- if (distance < 1)
- {
- if (Movimientos != 0) {
- CurrentMove++;
- Movimientos--;
- CurrentWayPoint++;
- }
- }
- else
- {
- this.transform.position = Vector3.SmoothDamp(this.transform.position, ExistWayPoints[CurrentWayPoint].position, ref refMove, SmoothMove * Time.deltaTime);
- }
- }
- }
- public void SumarWayPoint (int ValorDelDado)
- {
- Movimientos = ValorDelDado;
- }
- }
Add Comment
Please, Sign In to add comment