Skip to content

Instantly share code, notes, and snippets.

@arkilis
Last active April 13, 2018 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arkilis/2cc95d76d8f7ee994f44c6ab20875a53 to your computer and use it in GitHub Desktop.
Save arkilis/2cc95d76d8f7ee994f44c6ab20875a53 to your computer and use it in GitHub Desktop.
camera follow
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