summaryrefslogtreecommitdiff
path: root/Assets/ProFlares/DemoScripts/SpinInput.cs
blob: 195917f8814f68ea61249a855d5874c53fb8da74 (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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/// ProFlares - v1.08 - Copyright 2014-2015 All rights reserved - ProFlares.com


/// <summary>
/// SpinInput.cs
/// Rotates a transform based on click dragging. Works on ether X or Y Axis. Y Axis can be limited.
/// </summary>

using UnityEngine;
using System.Collections;

namespace ProFlares {
public class SpinInput : MonoBehaviour {
	
	private Transform thisTransform;
	
	float xVerlo;
	
	float targetVerloX;
	float lastX;
	float currentX;
	
	float offsetX;
	
	float finalVeloX;
	
	float tempVeloX;
		
	float YVerlo;
	
	float targetVerloY;
	float lastY;
	float currentY;
	
	float offsetY;
	
	float finalVeloY;
	
	float tempVeloY;
	
	public int cropDist = 180;
	
	public float ResponseTime = 0.2f;
	
	public bool touchMode = true;
	void Start () {
		thisTransform = transform;
	}
		
	public bool X;
	
	public bool Y;
	
 
	void LateUpdate () {
		
		
		if(X){
                    
            if(Input.GetMouseButtonDown(0)){
                //				print("MouseDown");
                lastX = 0;
                currentX = 0;
                offsetX = Input.mousePosition.x;
            }
          
            
            if(Input.GetMouseButton(0)){
                
                lastX = currentX;
                currentX = Input.mousePosition.x-offsetX;
                
                targetVerloX = (currentX-lastX)*2;
				
				if((currentX-lastX > 1)||(currentX-lastX < -1)){
					 
				}
                targetVerloX = targetVerloX*3.5f;
                
            }else{
                
                targetVerloX = targetVerloX*0.95f;
            }
			finalVeloX = Mathf.Lerp(finalVeloX,targetVerloX,20*Time.deltaTime);
			
			thisTransform.Rotate(0,finalVeloX*Time.deltaTime,0);
        }
        
        
        
        if(Y){ 
                if(Input.GetMouseButtonDown(0)){
                    //				print("MouseDown");
                    lastY = 0;
                    currentY = 0;
                    offsetY = Input.mousePosition.y;
                }
                
                if(Input.GetMouseButton(0)){
                    
                    lastY = currentY;
                    currentY = Input.mousePosition.y-offsetY;
                    
                    targetVerloY = (currentY-lastY)*-2;
                    targetVerloY = targetVerloY*1.5f;
                    
                }else{
                    
                    targetVerloY = targetVerloY*0.95f;
                }

				
			finalVeloY = Mathf.Lerp(finalVeloY,targetVerloY,20*Time.deltaTime);
			
			
			thisTransform.Rotate(finalVeloY*Time.deltaTime,0,0);
			

			Quaternion newrotation = thisTransform.rotation;
			
			newrotation.x = Mathf.Clamp(newrotation.x,-0.1f,0.3f);
			
			thisTransform.rotation = newrotation;
 
        }
        
	}
	}
}