Unity/연습
[Unity] 자동차로 이것저것
tmd1
2023. 1. 6. 19:24
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FollowPlayer : MonoBehaviour
{
public GameObject player;
private Vector3 offset = new Vector3(0, 5, -7);
private float turnSpeed = 40.0f;
private float horizontalInput;
private bool pressF = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void LateUpdate()
{
horizontalInput = Input.GetAxis("Horizontal");
transform.position = player.transform.position + offset;
if (Input.GetKey(KeyCode.F))
{
if(pressF == true)
{
pressF = false;
}
else
{
transform.rotation = Quaternion.Euler(0, 0, 0);
pressF = true;
}
}
if(pressF == true)
{
offset = new Vector3(0, 1.8f, 2);
transform.Rotate(Vector3.up, Time.deltaTime * turnSpeed * horizontalInput);
}
else
{
transform.rotation = Quaternion.Euler(20, 0, 0);
offset = new Vector3(0, 5, -7);
}
}
}
키를 눌러 시점을 변경하는 것을 구현하려 했는데 많은 어려움이 존재 했다.
카메라 두개를 사용하여 온오프 하는 방법도 있는데 자세히 알아봐야 할듯