Created
November 16, 2017 12:44
-
-
Save gonztirado/46fd1f980d532efc4ccf7f4c947c58fa to your computer and use it in GitHub Desktop.
Sigue la camara al personaje manteniendo siempre un desplazamiento con respecto a donde está avanzando
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 UnityEngine; | |
using System.Collections; | |
public class CameraFollower : MonoBehaviour | |
{ | |
public Transform target; | |
public float initOffsetX; | |
public float initOffsetY; | |
public float moveToRightOffset; | |
public float moveToLeftOffset; | |
public float moveToBottomOffset; | |
public float moveOffset; | |
public float minCamaraPositionX; | |
public float minCamaraPositionY; | |
private float xOffset; | |
private float yOffset; | |
private void Awake() | |
{ | |
this.xOffset = initOffsetX; | |
this.yOffset = initOffsetY; | |
} | |
void Update() | |
{ | |
float newPositionX = target.position.x + xOffset; | |
float newPositionY = target.position.y + yOffset; | |
if (newPositionX < minCamaraPositionX) | |
newPositionX = minCamaraPositionX; | |
if (newPositionY < minCamaraPositionY) | |
newPositionY = minCamaraPositionY; | |
transform.position = new Vector3(newPositionX, newPositionY, transform.position.z); | |
} | |
public void FollowUpOffset() | |
{ | |
if (moveToBottomOffset < this.yOffset) | |
{ | |
this.xOffset -= moveOffset; | |
if (this.yOffset < moveToBottomOffset) | |
this.yOffset = moveToBottomOffset; | |
} | |
} | |
public void MoveToLeftOffset() | |
{ | |
if (moveToLeftOffset < this.xOffset) | |
{ | |
this.xOffset -= moveOffset; | |
if (this.xOffset < moveToLeftOffset) | |
this.xOffset = moveToLeftOffset; | |
} | |
} | |
public void MoveToRightOffset() | |
{ | |
if (moveToRightOffset > this.xOffset) | |
{ | |
this.xOffset += moveOffset; | |
if (this.xOffset > moveToRightOffset) | |
this.xOffset = moveToRightOffset; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment