blob: 960734a79b1a4314a7f8d115e3ead530baa20937 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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;
}
}
|