客観視点のカメラを作成

第三者視点のカメラ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ThirdPersonCamera : MonoBehaviour {
public float smooth = 3.0f;
private Transform standardPos;
private Transform frontPos;
// ★ポイント
private bool bQuickSwitch = false;
void Start () {
// (テクニック)1台のカメラで複数の視点を実現する。
standardPos = GameObject.Find("CamPos").transform;
frontPos = GameObject.Find ("FrontPos").transform;
// カメラの初期位置は「standardPos」の位置
transform.position = standardPos.position;
// 初期の向きは「standardPos」の向き
transform.forward = standardPos.forward;
}
// カメラの切り替えはこの中で行う。
void FixedUpdate () {
if (Input.GetKey (KeyCode.F)) {
SetCameraFrontPositionView ();
} else {
SetCameraNomalPositionView ();
}
}
void SetCameraNomalPositionView(){
if (bQuickSwitch == false) {
transform.position = Vector3.Lerp (transform.position, standardPos.position, Time.fixedDeltaTime * smooth);
transform.forward = Vector3.Lerp (transform.forward, standardPos.forward, Time.fixedDeltaTime * smooth);
} else { // フロントポジションからスタンダードポジションには素早く移動する。
transform.position = standardPos.position;
transform.forward = standardPos.forward;
bQuickSwitch = false;
}
}
void SetCameraFrontPositionView(){
bQuickSwitch = true;
transform.position = frontPos.position;
transform.forward = frontPos.forward;
}
}




第三者視点のカメラ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ThirdPersonCamera : MonoBehaviour {
public float smooth = 3.0f;
private Transform standardPos;
private Transform frontPos;
// ★ポイント
private bool bQuickSwitch = false;
void Start () {
// (テクニック)1台のカメラで複数の視点を実現する。
standardPos = GameObject.Find("CamPos").transform;
frontPos = GameObject.Find ("FrontPos").transform;
// カメラの初期位置は「standardPos」の位置
transform.position = standardPos.position;
// 初期の向きは「standardPos」の向き
transform.forward = standardPos.forward;
}
// カメラの切り替えはこの中で行う。
void FixedUpdate () {
if (Input.GetKey (KeyCode.F)) {
SetCameraFrontPositionView ();
} else {
SetCameraNomalPositionView ();
}
}
void SetCameraNomalPositionView(){
if (bQuickSwitch == false) {
transform.position = Vector3.Lerp (transform.position, standardPos.position, Time.fixedDeltaTime * smooth);
transform.forward = Vector3.Lerp (transform.forward, standardPos.forward, Time.fixedDeltaTime * smooth);
} else { // フロントポジションからスタンダードポジションには素早く移動する。
transform.position = standardPos.position;
transform.forward = standardPos.forward;
bQuickSwitch = false;
}
}
void SetCameraFrontPositionView(){
bQuickSwitch = true;
transform.position = frontPos.position;
transform.forward = frontPos.forward;
}
}



客観視点のカメラを作成