CameraScript.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using UnityEngine;
  2. using UnityEngine.Serialization;
  3. public class CameraScript : MonoBehaviour
  4. {
  5. public float damping = 1.5f;
  6. public Vector3 offset = new Vector3(0f, 0f, 0f);
  7. public Transform player;
  8. private int lastX;
  9. [SerializeField] private bool showCursor;
  10. private Animator _cameraAnimator;
  11. public Texture2D cursorTexture;
  12. public CursorMode cursorMode = CursorMode.Auto;
  13. public Vector2 hotSpot = Vector2.zero;
  14. void Start()
  15. {
  16. if (showCursor)
  17. {
  18. Cursor.SetCursor(cursorTexture, hotSpot, cursorMode);
  19. Cursor.visible = true;
  20. }
  21. //_isActive = false;
  22. _cameraAnimator = GetComponent<Animator>();
  23. lastX = Mathf.RoundToInt(player.position.x);
  24. }
  25. public void ShakeCamera()
  26. {
  27. _cameraAnimator.SetTrigger("shake");
  28. }
  29. public void PlayerWinner()
  30. {
  31. offset = new Vector3(0f, 4f, -3f);
  32. }
  33. public void SetCameraPosition(Vector3 camPosition)
  34. {
  35. offset = camPosition;
  36. }
  37. public void StartGame()
  38. {
  39. offset = new Vector3(0f, 9f, -7.5f);
  40. //_isActive = true;
  41. }
  42. void FixedUpdate()
  43. {
  44. int currentX = Mathf.RoundToInt(player.position.x);
  45. lastX = Mathf.RoundToInt(player.position.x);
  46. Vector3 target;
  47. target = new Vector3(player.position.x + offset.x, player.position.y + offset.y, player.position.z + offset.z);
  48. Vector3 currentPosition;
  49. // if (_isActive)
  50. // {
  51. currentPosition = Vector3.Lerp(transform.position, target, damping * Time.deltaTime);
  52. transform.position = currentPosition;
  53. // }
  54. }
  55. }