Created
June 22, 2023 22:47
-
-
Save NotStonee/209c878c2f748cac9dce5e09acea9ab1 to your computer and use it in GitHub Desktop.
unity camera follow script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class cameraFollow : MonoBehaviour | |
{ | |
public float FollowSpeed = 2f; | |
public float yOffset =1f; | |
public Transform target; | |
// Update is called once per frame | |
void FixedUpdate() | |
{ | |
Vector3 newPos = new Vector3(target.position.x,target.position.y + yOffset,-10f); | |
transform.position = Vector3.Slerp(transform.position,newPos,FollowSpeed*Time.deltaTime); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment