daily pastebin goal
52%
SHARE
TWEET

Chodzenie.cs

a guest Aug 21st, 2018 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5.  
  6. [RequireComponent(typeof(AudioSource))]
  7. public class Chodzenie : NetworkBehaviour {
  8.  
  9.    public Transform Character;
  10.     public int Speed;
  11.    public Rigidbody rb;
  12.     public AudioSource src;
  13.     public AudioClip clip;
  14.     public bool isGrounded;
  15.    
  16.  
  17.    
  18.    
  19.  
  20.     // Use this for initialization
  21.     void Start () {
  22.  
  23.         src = GetComponent<AudioSource>();
  24.        
  25.     }
  26.    
  27.     // Update is called once per frame
  28.     void Update () {
  29.  
  30.             MoveForward();
  31.             MoveBackward();
  32.             MoveLeft();          
  33.             MoveRight();
  34.             Jump();
  35.  
  36.         if (!isLocalPlayer)
  37.         {
  38.             return;
  39.         }
  40.  
  41.  
  42.     }
  43.  
  44.     void MoveForward()
  45.     {
  46.         if (Input.GetKey(KeyCode.W) && isLocalPlayer)
  47.         {
  48.             Character.Translate(new Vector3(-Time.deltaTime * Speed, 0f, 0f));
  49.             src.clip = clip;
  50.             src.PlayDelayed(10);
  51.         }
  52.        
  53.     }
  54.  
  55.     void MoveBackward()
  56.     {
  57.         if (Input.GetKey(KeyCode.S) && isLocalPlayer)
  58.         {
  59.             Character.Translate(new Vector3(Time.deltaTime * Speed, 0f, 0F));
  60.         }
  61.     }
  62.  
  63.     void MoveRight()
  64.     {
  65.         if (Input.GetKey(KeyCode.D) && isLocalPlayer)
  66.         {
  67.             Character.Translate(new Vector3(0f, 0f, Time.deltaTime * Speed));
  68.         }
  69.     }
  70.  
  71.     void MoveLeft()
  72.     {
  73.         if (Input.GetKey(KeyCode.A) && isLocalPlayer)
  74.         {
  75.             Character.Translate(new Vector3(0f, 0f, -Time.deltaTime * Speed));
  76.         }
  77.     }
  78.  
  79.     void Jump()
  80.     {
  81.  
  82.         if(Input.GetKeyDown(KeyCode.Space) && isLocalPlayer && isGrounded==true)
  83.         {
  84.                 GetComponent<Rigidbody>().AddForce(transform.up * 6, ForceMode.Impulse);    
  85.         }
  86.     }
  87.  
  88.      void OnCollisionEnter(Collision collision)
  89.     {
  90.         if(collision.gameObject.tag == "floor")
  91.         {
  92.             isGrounded = true;
  93.         }
  94.     }
  95.  
  96.     void OnCollisionExit(Collision collision)
  97.     {
  98.         if (collision.gameObject.tag == "floor")
  99.         {
  100.             isGrounded = false;
  101.         }
  102.     }
  103.  
  104.    
  105.        
  106.    
  107.  
  108.  
  109. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top