Last active
April 13, 2018 22:50
-
-
Save arkilis/2cc95d76d8f7ee994f44c6ab20875a53 to your computer and use it in GitHub Desktop.
camera follow
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 { | |
// assign the player (pink cube) | |
public Transform player; | |
// offset is used to put the main camra a bit behind the player (pink cube) | |
private Vector3 offset; | |
void Start () { | |
//Calculate and store the offset value by getting the distance between the player's position and camera's position. | |
offset = transform.position - player.transform.position; | |
} | |
// Update is called once per frame | |
void FixedUpdate () { | |
transform.position = player.transform.position + offset; | |
Debug.Log (transform.position); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment