-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRCC_CameraCarSelection.cs
More file actions
94 lines (62 loc) · 1.85 KB
/
Copy pathRCC_CameraCarSelection.cs
File metadata and controls
94 lines (62 loc) · 1.85 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//----------------------------------------------
// Realistic Car Controller
//
// Copyright © 2015 BoneCracker Games
// http://www.bonecrackergames.com
//
//----------------------------------------------
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.EventSystems;
public class RCC_CameraCarSelection : MonoBehaviour{
public Transform target;
public float distance= 10.0f;
public float xSpeed= 250f;
public float ySpeed= 120f;
public float yMinLimit= -20f;
public float yMaxLimit= 80f;
private float x= 0f;
private float y= 0f;
private bool selfTurn = true;
private float selfTurnTime = 0f;
void Start (){
Vector3 angles= transform.eulerAngles;
x = angles.y;
y = angles.x;
}
void LateUpdate (){
if (target) {
if(selfTurn)
x += xSpeed / 2f * Time.deltaTime;
y = ClampAngle(y, yMinLimit, yMaxLimit);
Quaternion rotation= Quaternion.Euler(y, x, 0);
Vector3 position= rotation * new Vector3(0f, 0f, -distance) + target.position;
transform.rotation = rotation;
transform.position = position;
if (selfTurnTime <= 1f)
selfTurnTime += Time.deltaTime;
if (selfTurnTime >= 1f)
selfTurn = true;
}
}
static float ClampAngle ( float angle , float min , float max ){
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp (angle, min, max);
}
public void OnDrag(BaseEventData data){
PointerEventData pointerData = data as PointerEventData;
x += pointerData.delta.x * xSpeed * 0.02f;
y -= pointerData.delta.y * ySpeed * 0.02f;
y = ClampAngle(y, yMinLimit, yMaxLimit);
Quaternion rotation= Quaternion.Euler(y, x, 0);
Vector3 position= rotation * new Vector3(0f, 0f, -distance) + target.position;
transform.rotation = rotation;
transform.position = position;
selfTurn = false;
selfTurnTime = 0f;
}
}