Синтаксис:
Используется csharp
using UnityEngine;
[AddComponentMenu("Camera-Control/Smooth Follow")]
public class SmoothFollow : MonoBehaviour
{
public Transform target;
public float distance = 10.0f;
public float height = 5.0f;
public float heightDamping = 2.0f;
public float rotationDamping = 3.0f;
void LateUpdate ()
{
if (!target)
return;
float wantedRotationAngle = target.eulerAngles.y;
float wantedHeight = target.position.y + height;
float currentRotationAngle = transform.eulerAngles.y;
float currentHeight = transform.position.y;
currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);
Quaternion currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
transform.position = target.position;
transform.position -= currentRotation * Vector3.forward * distance;
transform.position = new Vector3(transform.position.x, currentHeight, transform.position.z);
transform.LookAt (target);
}
}
[AddComponentMenu("Camera-Control/Smooth Follow")]
public class SmoothFollow : MonoBehaviour
{
public Transform target;
public float distance = 10.0f;
public float height = 5.0f;
public float heightDamping = 2.0f;
public float rotationDamping = 3.0f;
void LateUpdate ()
{
if (!target)
return;
float wantedRotationAngle = target.eulerAngles.y;
float wantedHeight = target.position.y + height;
float currentRotationAngle = transform.eulerAngles.y;
float currentHeight = transform.position.y;
currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);
Quaternion currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
transform.position = target.position;
transform.position -= currentRotation * Vector3.forward * distance;
transform.position = new Vector3(transform.position.x, currentHeight, transform.position.z);
transform.LookAt (target);
}
}
и сам скрипт:
Синтаксис:
Используется csharp
using UnityEngine;
using System;
[AddComponentMenu("Camera-Control/Change Point Of View")]
[RequireComponent(typeof(SmoothFollow))]
public class ChangePointOfView : MonoBehaviour
{
public int curentPoV;
public PoV[] points;
private SmoothFollow cameraScript;
[Serializable()]
public class PoV
{
public Transform target;
public float distance;
public float height;
public float heightDamping;
public float rotationDamping;
}
void Start ()
{
cameraScript = gameObject.GetComponent<SmoothFollow> ();
}
void Update ()
{
if (points == null)
return;
if (Input.GetKeyDown (KeyCode.C)) {
Debug.Log ("Change View");
curentPoV++;
curentPoV = (int)Mathf.Repeat (curentPoV, points.Length);
PoV pov = points[curentPoV];
cameraScript.target = pov.target;
cameraScript.distance = pov.distance;
cameraScript.height = pov.height;
cameraScript.heightDamping = pov.heightDamping;
cameraScript.rotationDamping = pov.rotationDamping;
}
}
void OnGUI()
{
GUI.Label(new Rect(0,0, 200, 20), "C - change camer");
}
}
using System;
[AddComponentMenu("Camera-Control/Change Point Of View")]
[RequireComponent(typeof(SmoothFollow))]
public class ChangePointOfView : MonoBehaviour
{
public int curentPoV;
public PoV[] points;
private SmoothFollow cameraScript;
[Serializable()]
public class PoV
{
public Transform target;
public float distance;
public float height;
public float heightDamping;
public float rotationDamping;
}
void Start ()
{
cameraScript = gameObject.GetComponent<SmoothFollow> ();
}
void Update ()
{
if (points == null)
return;
if (Input.GetKeyDown (KeyCode.C)) {
Debug.Log ("Change View");
curentPoV++;
curentPoV = (int)Mathf.Repeat (curentPoV, points.Length);
PoV pov = points[curentPoV];
cameraScript.target = pov.target;
cameraScript.distance = pov.distance;
cameraScript.height = pov.height;
cameraScript.heightDamping = pov.heightDamping;
cameraScript.rotationDamping = pov.rotationDamping;
}
}
void OnGUI()
{
GUI.Label(new Rect(0,0, 200, 20), "C - change camer");
}
}
Как им пользоваться:
1) вешаем скрипт на камеру;
2) создаем точки расположения камеры при помощи пустых объектов;
3) заполняем параметр points в инспекторе:
пример:
HTML код для вашего блога :