[TASK] Show collected duck stickers
This commit is contained in:
8
Assets/Scripts/Camera.meta
Normal file
8
Assets/Scripts/Camera.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 689794eb882594347a2210bf619fac6c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
60
Assets/Scripts/Camera/TouchCamera.cs
Normal file
60
Assets/Scripts/Camera/TouchCamera.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
// Just add this script to your camera. It doesn't need any configuration.
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
public class TouchCamera : MonoBehaviour {
|
||||
Vector2?[] oldTouchPositions = {
|
||||
null,
|
||||
null
|
||||
};
|
||||
Vector2 oldTouchVector;
|
||||
float oldTouchDistance;
|
||||
|
||||
void Update() {
|
||||
if (Input.touchCount == 0) {
|
||||
oldTouchPositions[0] = null;
|
||||
oldTouchPositions[1] = null;
|
||||
}
|
||||
else if (Input.touchCount == 1) {
|
||||
if (oldTouchPositions[0] == null || oldTouchPositions[1] != null) {
|
||||
oldTouchPositions[0] = Input.GetTouch(0).position;
|
||||
oldTouchPositions[1] = null;
|
||||
}
|
||||
else {
|
||||
Vector2 newTouchPosition = Input.GetTouch(0).position;
|
||||
|
||||
transform.position += transform.TransformDirection((Vector3)((oldTouchPositions[0] - newTouchPosition) * GetComponent<Camera>().orthographicSize / GetComponent<Camera>().pixelHeight * 2f));
|
||||
|
||||
oldTouchPositions[0] = newTouchPosition;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (oldTouchPositions[1] == null) {
|
||||
oldTouchPositions[0] = Input.GetTouch(0).position;
|
||||
oldTouchPositions[1] = Input.GetTouch(1).position;
|
||||
oldTouchVector = (Vector2)(oldTouchPositions[0] - oldTouchPositions[1]);
|
||||
oldTouchDistance = oldTouchVector.magnitude;
|
||||
}
|
||||
else {
|
||||
Vector2 screen = new Vector2(GetComponent<Camera>().pixelWidth, GetComponent<Camera>().pixelHeight);
|
||||
|
||||
Vector2[] newTouchPositions = {
|
||||
Input.GetTouch(0).position,
|
||||
Input.GetTouch(1).position
|
||||
};
|
||||
Vector2 newTouchVector = newTouchPositions[0] - newTouchPositions[1];
|
||||
float newTouchDistance = newTouchVector.magnitude;
|
||||
|
||||
transform.position += transform.TransformDirection((Vector3)((oldTouchPositions[0] + oldTouchPositions[1] - screen) * GetComponent<Camera>().orthographicSize / screen.y));
|
||||
transform.localRotation *= Quaternion.Euler(new Vector3(0, 0, Mathf.Asin(Mathf.Clamp((oldTouchVector.y * newTouchVector.x - oldTouchVector.x * newTouchVector.y) / oldTouchDistance / newTouchDistance, -1f, 1f)) / 0.0174532924f));
|
||||
GetComponent<Camera>().orthographicSize *= oldTouchDistance / newTouchDistance;
|
||||
transform.position -= transform.TransformDirection((newTouchPositions[0] + newTouchPositions[1] - screen) * GetComponent<Camera>().orthographicSize / screen.y);
|
||||
|
||||
oldTouchPositions[0] = newTouchPositions[0];
|
||||
oldTouchPositions[1] = newTouchPositions[1];
|
||||
oldTouchVector = newTouchVector;
|
||||
oldTouchDistance = newTouchDistance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Camera/TouchCamera.cs.meta
Normal file
11
Assets/Scripts/Camera/TouchCamera.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ade537fc62d5c974cb84efe75fbc9f08
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user