Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class FishMoveAquarium : MonoBehaviour {
- [Header("Amplitude das rotacoes em torno de cada eixo")]
- [Header("Eixo Z")]
- [SerializeField] float maximoAnguloZ;
- [SerializeField] float minimoAnguloZ;
- [Header("Velocidades de rotacao")]
- [SerializeField] float velocidadeDeRotacaoZ;
- [Header("em torno de quais eixos deve rodar?")]
- [SerializeField] bool z;
- bool rodarZPositivamente;
- bool movimentar;
- bool colidiu;
- float rotZ;
- public float speed;
- private float distance;
- private Rigidbody rb;
- // Use this for initialization
- void Start() {
- rb = GetComponent<Rigidbody>();
- colidiu = false;
- movimentar = true;
- rotZ = transform.rotation.eulerAngles.z;
- }
- // Update is called once per frame
- void Update() {
- if (colidiu)
- {
- Colidiu();
- }
- else
- {
- NaoColidiu();
- }
- }
- void OnTriggerEnter(Collider other)
- {
- if (other.gameObject.tag == "wallRight" || other.gameObject.tag == "wallLeft")
- {
- colidiu = true;
- AplicaRotacoes();
- }
- }
- void OnTriggerExit(Collider other)
- {
- colidiu = false;
- NaoColidiu();
- }
- void AplicaRotacoes()
- {
- if (rotZ < minimoAnguloZ)
- {
- rodarZPositivamente = true;
- }
- if (rotZ > maximoAnguloZ)
- {
- rodarZPositivamente = false;
- }
- if (z)
- {
- if (rodarZPositivamente)
- {
- movimentar = false;
- transform.Rotate(0, 0, velocidadeDeRotacaoZ * Time.deltaTime);
- rotZ += Time.deltaTime * velocidadeDeRotacaoZ;
- }
- else
- {
- movimentar = false;
- transform.Rotate(0, 0, -velocidadeDeRotacaoZ * Time.deltaTime);
- rotZ -= Time.deltaTime * velocidadeDeRotacaoZ;
- }
- if (!rodarZPositivamente)
- {
- movimentar = true;
- transform.Translate(0, speed * Time.deltaTime, 0);
- }
- else
- {
- movimentar = true;
- transform.Translate(0, -speed * Time.deltaTime, 0);
- }
- }
- }
- void Colidiu()
- {
- if (colidiu)
- {
- AplicaRotacoes();
- }
- else
- {
- NaoColidiu();
- }
- }
- void NaoColidiu()
- {
- if (!colidiu)
- {
- transform.Translate(0, speed * Time.deltaTime, 0);
- }
- else
- {
- transform.Translate(0, -speed * Time.deltaTime, 0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement