Skip to content

Instantly share code, notes, and snippets.

@sirokm007n
Created January 31, 2017 11:17
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 sirokm007n/df878a4cf4a4290502be0d2de5645a4e to your computer and use it in GitHub Desktop.
Save sirokm007n/df878a4cf4a4290502be0d2de5645a4e to your computer and use it in GitHub Desktop.
ブログ『Unity講座chap3』スクリプト『Follow.cs』
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