Thursday, February 7, 2019

camera follow to player full script in unity 3d by allunityscripts

camera follow script unity

unity camera follow script
using UnityEngine;
using System.Collections;

public class Follow Player : MonoBehaviour {

    public GameObject player;       


    private Vector3 offset;         

    // Use this for initialization
    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;
    }
    
    // LateUpdate is called after Update each frame
    void LateUpdate () 
    {
        // Set the position of the camera's transform to be the same as the player's, but offset by the calculated offset distance.
        transform.position = player.transform.position + offset;
    }
}

No comments:

Post a Comment