Diamond32_Tutoriales

Movimiento de dado

Jul 15th, 2022 (edited)
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.66 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class NPCMovement : MonoBehaviour
  6. {
  7.     public Transform WayPointsHolder;
  8.  
  9.  
  10.     [Header("No modificar")] public List<Transform> ExistWayPoints = new List<Transform>();
  11.     [Header("No modificar")] public int CurrentWayPoint;
  12.     Vector3 refMove;
  13.     public float SmoothMove = 100f;
  14.  
  15.     [Header("Estos seran los movimientos")]public int Movimientos;
  16.     [Header("No modificar")]public int CurrentMove;
  17.  
  18.     private void Start()
  19.     {
  20.         for (int i = 0; i < WayPointsHolder.childCount; i++)
  21.         {
  22.             ExistWayPoints.Add (WayPointsHolder.GetChild(i).transform);
  23.         }
  24.     }
  25.  
  26.     private void Update()
  27.     {
  28.         CurrentWayPoint = Mathf.Clamp (CurrentWayPoint, 0, ExistWayPoints.Count - 1);
  29.  
  30.         if (WayPointsHolder == null)
  31.         {
  32.             print ("<color=yellow> Por favor inserta el manager de los waypoints</color>");
  33.         }
  34.         else
  35.         {
  36.             float distance = Vector3.Distance (this.transform.position, ExistWayPoints[CurrentWayPoint].position);
  37.  
  38.             if (distance < 1)
  39.             {
  40.                 if (Movimientos != 0) {
  41.                     CurrentMove++;
  42.                     Movimientos--;
  43.                     CurrentWayPoint++;
  44.                 }
  45.             }
  46.             else
  47.             {
  48.                 this.transform.position = Vector3.SmoothDamp(this.transform.position, ExistWayPoints[CurrentWayPoint].position, ref refMove, SmoothMove * Time.deltaTime);
  49.             }
  50.         }
  51.     }
  52.  
  53.  
  54.     public void SumarWayPoint (int ValorDelDado)
  55.     {
  56.         Movimientos = ValorDelDado;
  57.     }
  58. }
  59.  
Add Comment
Please, Sign In to add comment