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

41 lines
889 B
C#
Raw Normal View History

2024-04-07 14:17:09 +02:00
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;
2024-04-08 19:08:37 +02:00
public float Angle = 45.0f;
2024-04-07 14:17:09 +02:00
void Start()
{
Vector4 position = new Vector4(0, 0, -Distance, 1.0f);
2024-04-08 19:08:37 +02:00
Quaternion rotation = Quaternion.Euler(Angle, 0, 0);
Matrix4x4 mat = Matrix4x4.Rotate(rotation);
2024-04-07 14:17:09 +02:00
_camera.transform.localPosition = mat * position;
2024-04-08 19:08:37 +02:00
_camera.transform.localRotation = rotation;
2024-04-07 14:17:09 +02:00
transform.position = _character.transform.position;
}
// Update is called once per frame
void Update()
{
transform.position = _character.transform.position;
}
private void OnValidate()
{
Start();
}
}