GameVsJam/3d Prototyp/Assets/Scripts/CameraScript.cs

41 lines
889 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraScript : MonoBehaviour
{
[SerializeField]
private Character _character;
[SerializeField]
private Camera _camera;
public float Distance = 5.0f;
public float Angle = 45.0f;
void Start()
{
Vector4 position = new Vector4(0, 0, -Distance, 1.0f);
Quaternion rotation = Quaternion.Euler(Angle, 0, 0);
Matrix4x4 mat = Matrix4x4.Rotate(rotation);
_camera.transform.localPosition = mat * position;
_camera.transform.localRotation = rotation;
transform.position = _character.transform.position;
}
// Update is called once per frame
void Update()
{
transform.position = _character.transform.position;
}
private void OnValidate()
{
Start();
}
}