Je fais un jeu Android avec des commandes à l'écran, un joystick et des boutons. Pour orienté la caméra, j'utilise aussi le gyroscope du téléphone et un glissé sur l'écran pour orienter la vue.
Le problème est quand je veux utilisé le joystick la vue se retourne, du coup je veux inhiber le glissé sur l'écran lorsque l'appui se situe au niveau du joystick ou des boutons généré par CrossPlatformInput.
Voici le code associé à la caméra aujourd'hui :
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
public class RotateCamera : MonoBehaviour {
Vector3 FirstPoint;
Vector3 SecondPoint;
float xAngle;
float yAngle;
float xAngleTemp;
float yAngleTemp;
void Start()
{
Input.gyro.enabled = true;
xAngle = 0;
yAngle = 0;
transform.rotation = Quaternion.Euler(yAngle, xAngle, 0);
}
void Update()
{
if (!Input.gyro.enabled) Input.gyro.enabled = true;
transform.Rotate(-Input.gyro.rotationRateUnbiased.x, -Input.gyro.rotationRateUnbiased.y, 0);
float z = transform.eulerAngles.z;
transform.Rotate(0, 0, -z);
if (CrossPlatformInputManager.GetAxis("Horizontal") == 0 && CrossPlatformInputManager.GetAxis("Vertical") == 0)
{
if (Input.touchCount > 0)
{
if (Input.GetTouch(0).phase == TouchPhase.Began)
{
FirstPoint = Input.GetTouch(0).position;
xAngleTemp = xAngle;
yAngleTemp = yAngle;
}
if (Input.GetTouch(0).phase == TouchPhase.Moved)
{
SecondPoint = Input.GetTouch(0).position;
xAngle = xAngleTemp + (SecondPoint.x - FirstPoint.x) * 180 / Screen.width;
yAngle = yAngleTemp + (SecondPoint.y - FirstPoint.y) * 90 / Screen.height;
transform.rotation = Quaternion.Euler(-yAngle, xAngle, 0.0f);
}
}
}
}
}