Guest User

Untitled

a guest
Nov 18th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CameraFollower : MonoBehaviour
  5. {
  6.  
  7. public Transform target;
  8. public float initOffsetX;
  9. public float initOffsetY;
  10. public float moveToRightOffset;
  11. public float moveToLeftOffset;
  12. public float moveToBottomOffset;
  13. public float moveOffset;
  14.  
  15. public float minCamaraPositionX;
  16. public float minCamaraPositionY;
  17.  
  18. private float xOffset;
  19.  
  20. private float yOffset;
  21.  
  22. private void Awake()
  23. {
  24. this.xOffset = initOffsetX;
  25. this.yOffset = initOffsetY;
  26. }
  27.  
  28. void Update()
  29. {
  30. float newPositionX = target.position.x + xOffset;
  31. float newPositionY = target.position.y + yOffset;
  32. if (newPositionX < minCamaraPositionX)
  33. newPositionX = minCamaraPositionX;
  34.  
  35. if (newPositionY < minCamaraPositionY)
  36. newPositionY = minCamaraPositionY;
  37.  
  38. transform.position = new Vector3(newPositionX, newPositionY, transform.position.z);
  39. }
  40.  
  41. public void FollowUpOffset()
  42. {
  43. if (moveToBottomOffset < this.yOffset)
  44. {
  45. this.xOffset -= moveOffset;
  46. if (this.yOffset < moveToBottomOffset)
  47. this.yOffset = moveToBottomOffset;
  48. }
  49. }
  50.  
  51. public void MoveToLeftOffset()
  52. {
  53. if (moveToLeftOffset < this.xOffset)
  54. {
  55. this.xOffset -= moveOffset;
  56. if (this.xOffset < moveToLeftOffset)
  57. this.xOffset = moveToLeftOffset;
  58. }
  59. }
  60.  
  61. public void MoveToRightOffset()
  62. {
  63. if (moveToRightOffset > this.xOffset)
  64. {
  65. this.xOffset += moveOffset;
  66. if (this.xOffset > moveToRightOffset)
  67. this.xOffset = moveToRightOffset;
  68. }
  69. }
  70. }
Add Comment
Please, Sign In to add comment