Advertisement
johnnygoodguy2000

CameraController.cs

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