I have a round plane, that rotates in x and z axis. I need to trigger a special event every time when rotation is big enough.
Problem is that in one side it's from 0 to 90, while in other side it's 270 to 360.
using UnityEngine;
using System.Collections;
public class Contrr : MonoBehaviour {
public float speed = 100f;
public float startRotation;
public float newRotation;
private Vector3 Line1;
private Vector3 NewVector;
public float stackX;
public float stackY;
public Vector3 mousePos;
public Vector3 mousePosZero;
public GameObject Scene;
public float SceneX;
public float SceneZ;
void Start () {
GameObject Scene = GameObject.FindGameObjectWithTag ("Scene");
**if (Scene.transform.rotation.x > 270) {
SceneX = 360 - Scene.transform.rotation.x;
}
if (Scene.transform.rotation.z > 270) {
SceneZ = 360 - Scene.transform.rotation.z;
}
if (Scene.transform.rotation.x < 90) {
SceneX = Scene.transform.rotation.x;
}
if (Scene.transform.rotation.z < 90) {
SceneZ = Scene.transform.rotation.z;
}
startRotation = SceneX + SceneZ ;**
}
void FixedUpdate () {
mousePos = Input.mousePosition;
mousePos.x -= Screen.width/2;
mousePos.y -= Screen.height/2;
GetComponent ().force = new Vector3 (mousePos.x * 400, 0f, mousePos.y * 400 );
GameObject Scene = GameObject.FindGameObjectWithTag ("Scene");
**newRotation = SceneX + SceneZ;**
**if(Scene.transform.rotation.x>270){
SceneX = 360-Scene.transform.rotation.x;}
if(Scene.transform.rotation.z>270){
SceneZ = 360-Scene.transform.rotation.z;}
if(Scene.transform.rotation.x<90){
SceneX = Scene.transform.rotation.x;}
if(Scene.transform.rotation.z<90){
SceneZ = Scene.transform.rotation.z;}
if ( newRotation + 5 < startRotation ) {
GetComponent ().AddForce(transform.forward * 2000, ForceMode.Impulse);
print ("Booyaa");
}**
**startRotation = newRotation;**
**if(startRotation < newRotation){
startRotation = newRotation;}**
}
}
}
↧