Created
January 31, 2017 11:17
-
-
Save sirokm007n/df878a4cf4a4290502be0d2de5645a4e to your computer and use it in GitHub Desktop.
ブログ『Unity講座chap3』スクリプト『Follow.cs』
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 Follow : MonoBehaviour { | |
public GameObject target;//ターゲット(追尾対象)格納変数 | |
public float cameraSpeed;//スピード(カメラの速さ)格納変数 | |
Vector3 distance;//距離(ターゲットとどれくらいの距離を保つか)格納変数 | |
// Use this for initialization | |
void Start () { | |
distance = target.transform.position - transform.position; | |
} | |
// Update is called once per frame | |
void LateUpdate () { | |
Vector3 cameraDistance = target.transform.position - distance; | |
transform.position = Vector3.Lerp (transform.position,cameraDistance,Time.deltaTime * cameraSpeed); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment