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 Controller : MonoBehaviour {
- public GameObject idle;
- public Transform forward;
- public Transform backwards;
- public Transform left;
- public Transform right;
- public Transform lf;
- public Transform rf;
- public Transform lb;
- public Transform rb;
- public float moveSpeed;
- public float walkSpeed = 2;
- public float runSpeed = 4;
- public float rotationSpeed = 90.0f;
- public bool running = false;
- public bool walking = false;
- public Animation anim;
- public string idleAnim = "Idle";
- public string walkAnim = "Walk";
- public string runAnim = "Run";
- public string atak = "attack";
- public string roll = "rolling";
- public GameObject rTrail;
- public GameObject hTrail;
- public GameObject collider;
- public Rigidbody rigidbody;
- public bool canInputMovement = true;
- public bool cooldown;
- public bool rolling;
- public bool onGround;
- // Use this for initialization
- void Start () {
- anim.Play(idleAnim);
- }
- void OnTriggerEnter () {
- anim.Play(idleAnim);
- onGround = true;
- }
- void OnTriggerExit () {
- onGround = false;
- }
- // Update is called once per frame
- void Update () {
- if(Input.GetMouseButtonDown(0) && !cooldown){
- StartCoroutine(mandioca());
- }
- if(Input.GetKeyDown(KeyCode.Space) && !cooldown && onGround == true){
- rigidbody.velocity += 16 * Vector3.up;
- StartCoroutine(mandioca2());
- }
- if(Input.GetKeyDown(KeyCode.T) ){
- anim.Play("dance");
- }
- if(onGround == false){
- anim.Play("fall");
- }
- if(canInputMovement){
- if(Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.D)){
- transform.position += transform.forward * Time.deltaTime * moveSpeed;
- idle.transform.rotation = forward.transform.rotation;
- }
- if(Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.A)){
- transform.position += transform.forward * Time.deltaTime * moveSpeed;
- idle.transform.rotation = backwards.transform.rotation;
- }
- if(Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.W)){
- transform.position += transform.forward * Time.deltaTime * moveSpeed;
- idle.transform.rotation = left.transform.rotation;
- }
- if(Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S)){
- transform.position += transform.forward * Time.deltaTime * moveSpeed;
- idle.transform.rotation = right.transform.rotation;
- }
- if(Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.A)){
- transform.position += transform.forward * Time.deltaTime * moveSpeed;
- idle.transform.rotation = lf.transform.rotation;
- }
- if(Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.D)){
- transform.position += transform.forward * Time.deltaTime * moveSpeed;
- idle.transform.rotation = rf.transform.rotation;
- }
- if(Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.A)){
- transform.position += transform.forward * Time.deltaTime * moveSpeed;
- idle.transform.rotation = lb.transform.rotation;
- }
- if(Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.D)){
- transform.position += transform.forward * Time.deltaTime * moveSpeed;
- idle.transform.rotation = rb.transform.rotation;
- }
- //GetComponent<Rigidbody>().velocity = transform.forward * moveSpeed * movePlayer;
- }
- if(walking == true){
- moveSpeed = walkSpeed;
- }
- if(running == true){
- rTrail.SetActive(true);
- moveSpeed = runSpeed;
- }else{
- rTrail.SetActive(false);
- }
- if(canInputMovement){
- //ANIMATIONS ==============================================
- //start_idlle_master
- if(Input.GetKeyUp(KeyCode.D) || Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.S) || Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.LeftShift)){
- anim.CrossFade(idleAnim);
- }
- if(!cooldown && Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.A) && Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.LeftShift)){
- running = true;
- anim.CrossFade(runAnim);
- }else{
- running = false;
- }
- //walk_forward
- if(!cooldown && Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.LeftShift)){
- walking = true;
- anim.CrossFade(walkAnim);
- }else{
- walking = false;
- }
- }
- }
- public IEnumerator mandioca(){
- anim.Play(atak);
- cooldown = true;
- //canInputMovement = false;
- collider.SetActive(true);
- hTrail.SetActive(true);
- yield return new WaitForSeconds(0.25f);
- collider.SetActive(false);
- if(onGround == true && walking == true){
- anim.CrossFade(walkAnim);
- }
- if(onGround == true && walking == false){
- anim.CrossFade(idleAnim);
- }
- if(onGround == false){
- anim.Play("fall");
- }
- hTrail.SetActive(false);
- canInputMovement = true;
- cooldown = false;
- }
- public IEnumerator mandioca2(){
- cooldown = true;
- rolling = true;
- yield return new WaitForSeconds(1.1f);
- rolling = false;
- canInputMovement = true;
- cooldown = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement