What my boss requires me to do is exactly same like this:
799eeb301b8c425fb23addfbe80add76
I have done the smooth swipe successfully.
However, i have no idea to do the “Change view” when you click the letter button.
I tried the :
void ChgView(int index)
{
rotationXAxis = cam[index - 1].transform.eulerAngles.x;
rotationYAxis = cam[index - 1].transform.eulerAngles.y;
}
but the result of rotation is not same as the reference…
And i want to do it in lerp way.
But i have no idea how to do it now. help me plz…
using UnityEngine;
using System.Collections;
public class OrbitCamera : MonoBehaviour
{
ColorPanel _colorPanel;
public GameObject target;
public Transform[] cam;
[SerializeField] float xSpeed = 15.0f;
[SerializeField] float ySpeed = 15.0f;
[SerializeField] float scrollSpeed = 5.0f;
float velocityX = 0.0f;
float velocityY = 0.0f;
float velocityScroll = 0.0f;
float rotationXAxis = 0.0f;
float rotationYAxis = 0.0f;
[SerializeField] float yMinLimit = -20f;
[SerializeField] float yMaxLimit = 80f;
public float distance = 1.5f;
void Start()
{
_colorPanel = GameObject.FindGameObjectWithTag("ColorPanel").GetComponent<ColorPanel>();
Vector3 camAngle = transform.eulerAngles;
rotationXAxis = camAngle.x;
rotationYAxis = camAngle.y;
}
void Update()
{
if(Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray, out hit))
{
hit.transform.GetComponent<MeshRenderer>().material = _colorPanel.currentMat;
}
}
}
void LateUpdate()
{
Orbit();
}
void Orbit()
{
if(target != null)
{
if(Input.GetMouseButton(0))
{
velocityX += xSpeed * Input.GetAxis("Mouse X") * distance * Time.deltaTime;
velocityY += ySpeed * Input.GetAxis("Mouse Y") * Time.deltaTime;
}
velocityScroll += scrollSpeed * Input.GetAxis("Mouse ScrollWheel") * Time.deltaTime;
rotationYAxis += velocityX;
rotationXAxis -= velocityY;
rotationXAxis = Mathf.Clamp(rotationXAxis, yMinLimit, yMaxLimit);
Quaternion toRotation = Quaternion.Euler(rotationXAxis, rotationYAxis, 0);
Quaternion rotation = toRotation;
distance = Vector3.Distance(transform.position, target.transform.position);
distance = Mathf.Clamp(distance - velocityScroll, 2, 5);
Vector3 position = rotation * new Vector3(0, 0, -distance) + target.transform.position;
transform.position = position;
transform.rotation = rotation;
velocityX = Mathf.Lerp(velocityX, 0, 2 * Time.deltaTime);
velocityY = Mathf.Lerp(velocityY, 0, 2 * Time.deltaTime);
velocityScroll = Mathf.Lerp(velocityScroll, 0, Time.deltaTime);
}
else
{
Debug.LogWarning("Orbit Camera - No Target Set");
}
}
void ChgView(int index)
{
rotationXAxis = cam[index - 1].transform.eulerAngles.x;
rotationYAxis = cam[index - 1].transform.eulerAngles.y;
}
}


