Skip to content

Instantly share code, notes, and snippets.

@valbeat
Created December 3, 2015 14:41
Show Gist options
  • Save valbeat/ce6969376533ff86d0d1 to your computer and use it in GitHub Desktop.
Save valbeat/ce6969376533ff86d0d1 to your computer and use it in GitHub Desktop.
Playerに追従するカメラ ref: http://qiita.com/kajitack/items/bab5cb649fe0cf6756d4
using UnityEngine;
using System.Collections;
public class CameraControl : MonoBehaviour {
private GameObject player = null;
private Vector3 offset = Vector3.zero;
void Start () {
player = GameObject.FindGameObjectWithTag("Player");
offset = transform.position - player.transform.position;
}
void LateUpdate () {
Vector3 newPosition = transform.position;
newPosition.x = player.transform.position.x + offset.x;
newPosition.y = player.transform.position.y + offset.y;
newPosition.z = player.transform.position.z + offset.z;
transform.position = newPosition;
}
}
transform.position = newPosition;
transform.position = Vector3.Lerp(transform.position,newPosition,5.0f * Time.deltaTime);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment