Last active
August 29, 2015 14:26
-
-
Save seamanmur/35a755a24ea4a0d53e1c to your computer and use it in GitHub Desktop.
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; | |
class CharTPSCamera : MonoBehaviour | |
{ | |
public static CharTPSCamera instance; | |
public Transform target; | |
public float Distance { get; set; } | |
//Минимальное расстояние от камеры до персонажа. | |
private const float _DISTANCE_MIN = 2f; | |
//Начальное расстояние от камеры до персонажа. У меня равно минимальному. Вы можете выбрать любое от минимального до максимального. | |
private const float _START_DISTANCE = _DISTANCE_MIN; | |
//Максимально расстояние от камеры до персонажа. | |
private const float _DISTANCE_MAX = 12f; | |
//Значение смещения мыши по оси X. | |
private float _mouseX; | |
//Значение смещения мыши по оси Y. | |
private float _mouseY; | |
//Рассчитанное желаемое расстояние от камеры до персонажа. | |
private float _desireDistance; | |
void Awake() | |
{ | |
instance = this; | |
} | |
void Start() | |
{ | |
//Вызываем метод, устанавливающий начальные значения переменных. | |
Reset(); | |
} | |
void LateUpdate() | |
{ | |
//Проверяем не исчезла лицель камеры, если исчезла ничего не делаем. | |
if (target == null) return; | |
//Вводим данные с мыши. | |
PlayerInput(); | |
//Рассчитываем желаемую позицию камеры. | |
CalcDesirePosition(); | |
//Смещаем камеру. | |
UpatePosition(); | |
} | |
private void PlayerInput() | |
{ | |
} | |
private void CalcDesirePosition() | |
{ | |
} | |
private Vector3 CalcPosition(float rotx, float roty, float distance) | |
{ | |
return Vector3.zero; | |
} | |
public void Reset() | |
{ | |
//Обнуляем данные, введенные с мыши. | |
_mouseX = 0; | |
_mouseY = 10f; | |
//Расстояние от камеры до персонажа равно стартовому. | |
Distance = _START_DISTANCE; | |
//Желаемое расстояние тоже равно стартовому. | |
_desireDistance = Distance; | |
} | |
private void UpatePosition() | |
{ | |
} | |
static public void GetCamera() | |
{ | |
GameObject tempCamera; | |
GameObject targetTemp; | |
CharTPSCamera myCamera; | |
if (Camera.main != null) tempCamera = Camera.main.gameObject; | |
else | |
{ | |
tempCamera = new GameObject("Main Camera"); | |
tempCamera.AddComponent(); | |
tempCamera.tag = "Main Camera"; | |
} | |
tempCamera.AddComponent(); | |
myCamera = tempCamera.GetComponent(); | |
targetTemp = GameObject.Find("targetLookAt"); | |
if (targetTemp == null) | |
{ | |
targetTemp = new GameObject("targetLookAt"); | |
targetTemp.transform.position = Vector3.zero; | |
} | |
myCamera.target = targetTemp.transform; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment