Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
- }
- }
Add Comment
Please, Sign In to add comment