Advertisement
Lerakelp

Untitled

Jun 26th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.14 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MovePlayer : MonoBehaviour
  6. {
  7.     public float moveSpeed = 20f;
  8.     public float turnSpeed = 0;
  9.  
  10.    
  11.     public GameObject Player;
  12.     public Animator Player_Animation;
  13.  
  14.     public bool run = false;
  15.  
  16.     public bool front =true ;
  17.     public bool back = false;
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  void Start()
  28.  {
  29.  
  30.      
  31.      
  32.      Player_Animation = Player.GetComponent<Animator>();
  33.  
  34.    
  35.  
  36.    
  37.        
  38.      
  39.  }
  40.  
  41.   void turnLeft()
  42.   {
  43.  
  44.  
  45.       if (front == true)
  46.       {
  47.            Player.transform.Rotate(Vector3.up, 180);
  48.            
  49.       }
  50.      
  51.  
  52.   }
  53.  
  54.   void TurnRight()
  55.   {
  56.  
  57.       if (back == true)
  58.       {
  59.            Player.transform.Rotate(Vector3.up, -180);
  60.            
  61.          
  62.  
  63.       }
  64.      
  65.  
  66.   }
  67.  
  68.  
  69.  
  70.    
  71.     void Update ()
  72.     {
  73.  
  74.      
  75.  
  76.         if(Input.GetKey(KeyCode.D) && run == false )
  77.         {
  78.             transform.Translate(Vector3.forward/2 * moveSpeed * Time.deltaTime);
  79.             Player_Animation.SetBool("Walk",true);
  80.              
  81.  
  82.              
  83.                 turnLeft();
  84.  
  85.            
  86.            
  87.            
  88.         }
  89.         else
  90.         {
  91.              Player_Animation.SetBool("Walk",false);
  92.              
  93.  
  94.         }
  95.            
  96.        
  97.         if(Input.GetKey(KeyCode.A))
  98.         {
  99.             transform.Translate(-Vector3.forward * moveSpeed/2 * Time.deltaTime);
  100.              
  101.              
  102.        
  103.             Player_Animation.SetBool("BackTurn",true);
  104.              
  105.  
  106.                 TurnRight();
  107.              
  108.              
  109.              
  110.            
  111.             // TeamKum_Animation.SetBool("Back",true);
  112.         }
  113.            
  114.           else
  115.         {
  116.               Player_Animation.SetBool("BackTurn",false);
  117.              
  118.           // TeamKum_Animation.SetBool("Back",false);
  119.         }
  120.        
  121.         if(Input.GetKey(KeyCode.G))
  122.         {
  123.              transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);
  124.              Player_Animation.SetBool("Atack1",true);
  125.  
  126.         }
  127.         else
  128.         {
  129.             Player_Animation.SetBool("Atack1",false);
  130.         }
  131.            
  132.  
  133.            
  134.        
  135.         if(Input.GetKey(KeyCode.RightArrow))
  136.         {
  137.             transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
  138.             // TeamKum_Animation.SetBool("Right",true);
  139.         }
  140.         else
  141.         {
  142.             // TeamKum_Animation.SetBool("Right",false);
  143.         }
  144.  
  145.  
  146.          if (Input.GetKey(KeyCode.Space))
  147.          {
  148.              Player_Animation.SetBool("Jump",true);
  149.          }  
  150.  
  151.          else
  152.         {
  153.                 Player_Animation.SetBool("Jump",false);
  154.          }
  155.  
  156.  
  157.           if (Input.GetKey(KeyCode.LeftShift))
  158.          {
  159.             moveSpeed = 45f;
  160.             transform.Translate(Vector3.forward/2 * moveSpeed * Time.deltaTime);
  161.              Player_Animation.SetBool("Run",true);
  162.              run = true;
  163.          }  
  164.  
  165.          else
  166.         {
  167.                 moveSpeed = 20f;
  168.                  Player_Animation.SetBool("Run",false);
  169.                  run = false;
  170.          }
  171.  
  172.  
  173.  
  174.  
  175.     }
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement