Created
August 12, 2020 00:51
-
-
Save muddokon/b42f81c68129f9656419231ea8f42f72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class LimitarVuelo : MonoBehaviour | |
{ | |
private float xOff; | |
[Header("Separacion del sprite con el borde de la pantalla en X izquierda:")] | |
public float xOffsetLeft; | |
[Header("Separacion del sprite con el borde de la pantalla en X derecha:")] | |
public float xOffsetRight; | |
[Header("Separacion del sprite con el borde de la pantalla en Y abajo:")] | |
public float yOffsetInf; | |
[Header("Separacion del sprite con el borde de la pantalla en Y arriba:")] | |
public float yOffsetSup; | |
void Awake() | |
{ | |
xOff = gameObject.GetComponent<SpriteRenderer>().size.x / 2; | |
playerRigidbody = GetComponent<Rigidbody>(); | |
} | |
void FixedUpdate() | |
{ | |
//Descomponemos el vector posición con Clamp para cada componente x,y,z dentro de los límites | |
transform.position = new Vector3(Mathf.Clamp(transform.position.x, xOffsetLeft, xOffsetRight), Mathf.Clamp(transform.position.y, yOffsetInf, yOffsetSup), transform.position.z); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment