From 88a6b32e792910e11451da18eb5fb8c103235842 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 28 Apr 2022 13:58:20 +0800 Subject: +misc --- .../Scripts/CharacterViewer.cs | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 SurvivalTest/Assets/ACS-17/Demo_Table_Animations/Scripts/CharacterViewer.cs (limited to 'SurvivalTest/Assets/ACS-17/Demo_Table_Animations/Scripts/CharacterViewer.cs') diff --git a/SurvivalTest/Assets/ACS-17/Demo_Table_Animations/Scripts/CharacterViewer.cs b/SurvivalTest/Assets/ACS-17/Demo_Table_Animations/Scripts/CharacterViewer.cs new file mode 100644 index 0000000..960734a --- /dev/null +++ b/SurvivalTest/Assets/ACS-17/Demo_Table_Animations/Scripts/CharacterViewer.cs @@ -0,0 +1,54 @@ +using UnityEngine; +using System.Collections; +using UnityEngine.UI; + +public class CharacterViewer : MonoBehaviour { + //Script control of the camera in the table animation + public Transform cameras; + + public Transform targetForCamera; + Vector3 deltaPosition; + Vector3 lastPosition = Vector3.zero; + bool rotating = false; + + void Awake () { + deltaPosition = cameras.position - targetForCamera.position; + deltaPosition = new Vector3(deltaPosition.x, deltaPosition.y - (-0.1f) * 5, deltaPosition.z +(-0.1f) * 8); + transform.Rotate(0, -300f * -170 / Screen.width, 0); + } + + void Update () { + if (Input.GetMouseButtonDown (0) && Input.mousePosition.x > Screen.width*0.25 ) { + lastPosition = Input.mousePosition; + rotating = true; + } + + if (Input.GetMouseButtonUp(0)) + rotating = false; + + if (rotating && Input.GetMouseButton(0)) + { + transform.Rotate(0, -300f * (Input.mousePosition - lastPosition).x / Screen.width, 0); + + } + + if (Input.GetAxis("Mouse ScrollWheel")!=0) + { + + var y = 0f; + if (Input.GetAxis("Mouse ScrollWheel") < 0 && deltaPosition.y < 18) y = Input.GetAxis("Mouse ScrollWheel"); + if (Input.GetAxis("Mouse ScrollWheel") > 0 && deltaPosition.y > 10f) y = Input.GetAxis("Mouse ScrollWheel"); + deltaPosition = new Vector3(deltaPosition.x, deltaPosition.y - y * 5, deltaPosition.z + y * 8); + } + + + lastPosition = Input.mousePosition; + } + + void LateUpdate () { + cameras.position += (targetForCamera.position + deltaPosition - cameras.position) * Time.unscaledDeltaTime * 5; + Vector3 relativePos = targetForCamera.position - cameras.position; + Quaternion rotation = Quaternion.LookRotation(relativePos); + cameras.rotation = rotation; + } +} -- cgit v1.1-26-g67d0