Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- [RequireComponent (typeof (BoxCollider))]
- [ExecuteInEditMode]
- public class Turbulencia : MonoBehaviour
- {
- private Vector3 originPosition;
- private Quaternion originRotation;
- public float shake_decay = 0.002f;
- public float shake_intensity = .3f;
- private float temp_shake_intensity = 0;
- public float TimePerchangeAxis;
- public Vector3 RotateForce;
- public float RotateSpeed;
- public bool isInZone;
- [SerializeField] bool right;
- [SerializeField] bool left;
- public Vector3 Zonesize;
- public string tag;
- public bool wait;
- BoxCollider bs
- {
- get
- {
- return GetComponent <BoxCollider>();
- }
- }
- public Transform avion;
- public Transform camera
- {
- get
- {
- return FindObjectOfType<Camera>().transform;
- }
- }
- public Color ZoneColor;
- private void Start()
- {
- StartCoroutine (VibradorDeLadoALado());
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.tag == tag)
- {
- avion = other.transform;
- }
- }
- private void OnTriggerExit(Collider other)
- {
- if (other.tag == tag)
- {
- avion = null;
- }
- }
- void Update()
- {
- bs.size = Zonesize;
- bs.isTrigger = true;
- if (temp_shake_intensity > 0)
- {
- camera.position = originPosition + Random.insideUnitSphere * temp_shake_intensity;
- camera.rotation = new Quaternion(
- originRotation.x + Random.Range(-temp_shake_intensity, temp_shake_intensity) * .2f,
- originRotation.y + Random.Range(-temp_shake_intensity, temp_shake_intensity) * .2f,
- originRotation.z + Random.Range(-temp_shake_intensity, temp_shake_intensity) * .2f,
- originRotation.w + Random.Range(-temp_shake_intensity, temp_shake_intensity) * .2f);
- temp_shake_intensity -= shake_decay;
- }
- if (Input.GetKey (KeyCode.G))
- {
- //Shake();
- }
- if (avion != null)
- {
- Shake();
- isInZone = true;
- }
- else
- {
- isInZone = false;
- }
- if (right)
- {
- Vector3 moveForce = new Vector3( RotateForce.x * Time.fixedDeltaTime * RotateSpeed,
- RotateForce.y * Time.fixedDeltaTime * RotateSpeed,
- RotateForce.z * Time.fixedDeltaTime * RotateSpeed);
- avion.Rotate(moveForce);
- }
- if (left)
- {
- Vector3 moveForcedd = new Vector3( -RotateForce.x * Time.fixedDeltaTime * RotateSpeed,
- -RotateForce.y * Time.fixedDeltaTime * RotateSpeed,
- -RotateForce.z * Time.fixedDeltaTime * RotateSpeed);
- avion.Rotate(moveForcedd);
- }
- }
- void Shake()
- {
- originPosition = camera.position;
- originRotation = camera.rotation;
- temp_shake_intensity = shake_intensity;
- }
- IEnumerator VibradorDeLadoALado()
- {
- while (true)
- {
- if (isInZone)
- {
- right = true;
- left = false;
- yield return new WaitForSeconds(TimePerchangeAxis);
- right = false;
- left = true;
- yield return new WaitForSeconds(TimePerchangeAxis);
- }
- yield return new WaitForSeconds(0.01f);
- }
- }
- public void OnDrawGizmos()
- {
- Gizmos.color = ZoneColor;
- Gizmos.DrawCube (this.transform.position, Zonesize);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement