Created
December 3, 2015 14:41
-
-
Save valbeat/ce6969376533ff86d0d1 to your computer and use it in GitHub Desktop.
Playerに追従するカメラ ref: http://qiita.com/kajitack/items/bab5cb649fe0cf6756d4
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 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; | |
} | |
} |
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
transform.position = newPosition; |
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
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