Advertisement
gomuani

enemigo

Jun 1st, 2022
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MovimientoPlataforma : MonoBehaviour
  6.  
  7.     {
  8.  
  9.     [SerializeField] private float velocidad;
  10.     [SerializeField] private Transform controladorSuelo;
  11.     [SerializeField] private float distancia;
  12.     [SerializeField] private bool moviendoDerecha;
  13.  
  14.     private Rigidbody2D rb;
  15.  
  16.     private void Start()
  17.  
  18.         {
  19.             rb = GetComponent<Rigidbody2D>();
  20.         }
  21.  
  22.         private void FixedUpdate()
  23.         {
  24.             RaycastHit2D informacionSuelo = Physics2D.Raycast(controladorSuelo.position, Vector2.down, distancia);
  25.             rb.velocity = new Vector2(velocidad, rb.velocity.y);
  26.             if (informacionSuelo == false)
  27.             {
  28.                 Girar();
  29.             }
  30.         }
  31.  
  32.         private void Girar()
  33.         {
  34.             moviendoDerecha = !moviendoDerecha;
  35.             transform.eulerAngles = new Vector3(0, transform.eulerAngles.y + 180, 0);
  36.             velocidad *= -1;
  37.          }
  38.  
  39.      
  40.       }
  41.  
  42.  
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement