unity
타겟지점까지 움직이고(smooth)
lookat을 처다보기
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VideoClick : MonoBehaviour
{
// Start is called before the first frame update
public Camera ActiveVideoCam;
public GameObject TargetPos;
public GameObject LookAtPoint;
PlayerMouseLook PlayLook;
public Vector3 InitPos;
public GameObject[] UnActiveGameObjects;
public float moveSpeed = 1;
private Vector3 velocity = Vector3.zero;
IEnumerator moveCam;
private void Start()
{
PlayLook = FindObjectOfType<PlayerMouseLook>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("1"))
{
ZoomIn();
}
if (Input.GetKeyDown("2"))
{
Out();
}
}
public void ZoomIn()
{
foreach (var x in UnActiveGameObjects)
{
x.SetActive(false);
}
PlayLook.enabled = false;
if (moveCam != null)
{
StopCoroutine(moveCam);
moveCam = null;
}
moveCam = SetZoomIn();
StartCoroutine(moveCam);
}
public void Out()
{
foreach (var x in UnActiveGameObjects)
{
x.SetActive(true);
}
PlayLook.enabled = true;
if (moveCam != null)
{
StopCoroutine(moveCam);
moveCam = null;
}
ActiveVideoCam.transform.position = InitPos;
}
IEnumerator SetZoomIn()
{
InitPos = ActiveVideoCam.transform.position;
//Vector3 originPosition = ActiveVideoCam.transform.position;
Vector3 target = TargetPos.transform.position;
while (true)
{
ActiveVideoCam.transform.position = Vector3.SmoothDamp(ActiveVideoCam.transform.position, target, ref velocity, moveSpeed);
ActiveVideoCam.transform.LookAt(LookAtPoint.transform.position);
if (Mathf.Abs(ActiveVideoCam.transform.position.x - target.x) < 0.1f)
break;
yield return new WaitForEndOfFrame();
}
}
}
댓글 없음:
댓글 쓰기