Hello everyone ,
I want to make a camera with swipe AND gyroscope controls , i want to have the rotation Z to 0 everytime , but when i combine my swipe and gyroscope , Z are not always equals to 0… Someone can help ?
Here my Swipe Code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Swipe : MonoBehaviour {
public float yRotation;
public float xRotation;
public static bool touche ;
private Vector3 rot;
GameObject camParent;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
touche = true;
Vector2 delta = Input.GetTouch(0).deltaPosition;
xRotation += delta.y * 0.5f;
yRotation += delta.x * 0.5f;
rot = new Vector3(transform.rotation.x - xRotation, transform.rotation.y + yRotation, 0);
this.transform.rotation = Quaternion.Euler(rot.x, rot.y, transform.rotation.z);
}
}
}
Here my Gyro code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Gyro : MonoBehaviour {
GameObject camParent;
Quaternion RotationGyro;
void Start ()
{
camParent = GameObject.FindGameObjectWithTag("Parent");
camParent.transform.position = this.transform.position;
this.transform.parent = camParent.transform;
Input.gyro.enabled = true;
}
void Update ()
{
// transform.localRotation = Quat;
this.transform.Rotate(-Input.gyro.rotationRateUnbiased.x, 0, 0);
camParent.transform.Rotate(0, -Input.gyro.rotationRateUnbiased.y, 0) ;
}
}
And here my last script , who disable or enable the swipe or the gyro if we touch the screen or not
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ScriptDisable : MonoBehaviour {
public Swipe Swipe;
public Gyro Gyro;
public static bool GyroOn;
// Use this for initialization
void Start ()
{
Gyro.enabled = true;
Swipe.enabled = false;
}
// Update is called once per frame
void Update()
{
if (Input.touchCount == 1 /*Input.GetTouch(0).phase == TouchPhase.Moved*/)
{
Gyro.enabled = false;
Swipe.enabled = true;
GyroOn = false;
}
else
{
Gyro.enabled = true;
GyroOn = true;
Swipe.enabled = false;
}
}
}
Please help me.
NB : In my scene , i have a empty who have the Swipe script and Disable Script , and his children is the camera with the gyro script.