unity 攝像機更換環繞的物體(二)
1.更換物體移動
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class CameraMove : MonoBehaviour
{
private CameraFixation Tagetpos;//例項化程式碼
private bool isTrue = false;//是否移動
void Start()
{
Tagetpos = Camera.main.GetComponent<CameraFixation>();
}
public void onMove(Vector3 cameraPos, Vector3 cameraRot)
{
isTrue = true;
Tagetpos.target.DOMove(cameraPos, 1f);
Tagetpos.target.DORotate(cameraRot, 1f);
StartCoroutine(AbFalse());
}
void Update()
{
if (isTrue)
{
Tagetpos.eulerAngles_y = Tagetpos.target.eulerAngles.x;
Tagetpos.eulerAngles_x = Tagetpos.target.eulerAngles.y;
Tagetpos.distance = Tagetpos.target.eulerAngles.z;
}
else
{
Tagetpos.target.rotation = Quaternion.Euler(Tagetpos.eulerAngles_y, Tagetpos.eulerAngles_x, Tagetpos.distance);
}
}
IEnumerator AbFalse()
{
yield return new WaitForSeconds(1f);
isTrue = false;
}
}
2.座標資訊的記錄。
public Vector3 pos;
public Vector3 rot;
private CameraMove cam;
void Start()
{
cam = Camera.main.gameObject.GetComponent<CameraMove>();
}
private void OnMouseDown()
{
cam.onMove(pos, rot);
}