Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class ControlesFox : MonoBehaviour {
- #region Properties
- private float runSpeed = 0.3f;
- private int contador = 0;
- private bool isControllable = true;
- private bool isJumping = false;
- public GUIText texto;
- public enum States{
- TURNING_LEFT,
- TURNING_RIGHT,
- NOT_TURNING
- }
- public States currentState = States.NOT_TURNING;
- private Vector3 CamPos = new Vector3();
- #endregion
- #region Functions
- void Start ()
- {
- animation["CorridaRaposa"].speed = 3f;
- animation["CorridaRaposa"].wrapMode = WrapMode.Loop;
- animation["CorridaRaposa"].blendMode = AnimationBlendMode.Blend;
- animation["PuloRaposa"].speed = 2.5f;
- animation["PuloRaposa"].blendMode = AnimationBlendMode.Blend;
- animation.Play("CorridaRaposa");
- texto.text = "Tigelas coletadas: 0";
- }
- void Update ()
- {
- GetPlayerInput ();
- if(currentState == States.TURNING_LEFT)
- {
- gameObject.transform.Rotate (0f,-2.5f,0f);
- }
- if (currentState == States.TURNING_RIGHT)
- {
- gameObject.transform.Rotate (0f, 2.5f,0f);
- }
- if (currentState == States.NOT_TURNING)
- {
- if (gameObject.transform.rotation.y < 0)
- {
- gameObject.transform.Rotate (0f, 1.5f, 0f);
- }
- if (gameObject.transform.rotation.y > 0)
- {
- gameObject.transform.Rotate (0f, -1.5f, 0f);
- }
- }
- MoveFox ();
- MoveCamera ();
- if (animation["PuloRaposa"].time >= 2.4)
- {
- isJumping = false;
- animation.Play ("CorridaRaposa");
- }
- texto.text = "Tigelas coletadas: " + contador.ToString();
- }
- void MoveCamera()
- {
- CamPos = gameObject.transform.position;
- Camera.main.transform.position = new Vector3(CamPos.x, CamPos.y + 1.9f, CamPos.z - 2.4f);
- }
- void MoveFox()
- {
- this.transform.Translate(0f,0f,runSpeed);
- if (this.transform.position.x > 48)
- {
- this.transform.Translate(-0.3f,0,0);
- }
- if (this.transform.position.x < 40)
- {
- this.transform.Translate(0.3f,0,0);
- }
- }
- void GetPlayerInput()
- {
- if (!isControllable)
- {
- Input.ResetInputAxes();
- }
- if (Input.GetKeyDown(KeyCode.LeftArrow))
- {
- currentState = States.TURNING_LEFT;
- }
- if (Input.GetKeyDown(KeyCode.RightArrow))
- {
- currentState = States.TURNING_RIGHT;
- }
- if(Input.GetKeyUp(KeyCode.LeftArrow) || Input.GetKeyUp(KeyCode.RightArrow))
- {
- currentState = States.NOT_TURNING;
- }
- if (Input.GetKeyDown (KeyCode.Space))
- {
- if (!isJumping)
- {
- isJumping = true;
- animation.Play("PuloRaposa");
- Input.ResetInputAxes();
- }
- else
- Input.ResetInputAxes();
- }
- }
- void OnCollisionEnter(Collision colisao)
- {
- if (colisao.gameObject.tag == "Tigela")
- {
- contador += 1;
- Debug.Log("Colidiu com tigela!");
- }
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment