Advertisement
johnnygoodguy2000

CameraController.cs

Apr 7th, 2024 (edited)
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class NewBehaviourScript : MonoBehaviour
  6. {
  7.     public PlayerController thePlayer;
  8.  
  9.     private Vector3 lastPlayerPosition;
  10.     private float distanceToMove;
  11.  
  12.     // Start is called before the first frame update
  13.     void Start()
  14.     {
  15.         thePlayer = FindObjectOfType<PlayerController>();
  16.         lastPlayerPosition = thePlayer.transform.position;
  17.     }
  18.  
  19.     // Update is called once per frame
  20.     void Update()
  21.     {
  22.         distanceToMove = thePlayer.transform.position.x - lastPlayerPosition.x;
  23.  
  24.         transform.position = new Vector3(transform.position.x + distanceToMove, transform.position.y, transform.position.z);
  25.         lastPlayerPosition = thePlayer.transform.position;
  26.     }
  27. }
  28.  
  29.  
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement