Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Networking;
- [RequireComponent(typeof(AudioSource))]
- public class Chodzenie : NetworkBehaviour {
- public Transform Character;
- public int Speed;
- public Rigidbody rb;
- public AudioSource src;
- public AudioClip clip;
- public bool isGrounded;
- // Use this for initialization
- void Start () {
- src = GetComponent<AudioSource>();
- }
- // Update is called once per frame
- void Update () {
- MoveForward();
- MoveBackward();
- MoveLeft();
- MoveRight();
- Jump();
- if (!isLocalPlayer)
- {
- return;
- }
- }
- void MoveForward()
- {
- if (Input.GetKey(KeyCode.W) && isLocalPlayer)
- {
- Character.Translate(new Vector3(-Time.deltaTime * Speed, 0f, 0f));
- src.clip = clip;
- src.PlayDelayed(10);
- }
- }
- void MoveBackward()
- {
- if (Input.GetKey(KeyCode.S) && isLocalPlayer)
- {
- Character.Translate(new Vector3(Time.deltaTime * Speed, 0f, 0F));
- }
- }
- void MoveRight()
- {
- if (Input.GetKey(KeyCode.D) && isLocalPlayer)
- {
- Character.Translate(new Vector3(0f, 0f, Time.deltaTime * Speed));
- }
- }
- void MoveLeft()
- {
- if (Input.GetKey(KeyCode.A) && isLocalPlayer)
- {
- Character.Translate(new Vector3(0f, 0f, -Time.deltaTime * Speed));
- }
- }
- void Jump()
- {
- if(Input.GetKeyDown(KeyCode.Space) && isLocalPlayer && isGrounded==true)
- {
- GetComponent<Rigidbody>().AddForce(transform.up * 6, ForceMode.Impulse);
- }
- }
- void OnCollisionEnter(Collision collision)
- {
- if(collision.gameObject.tag == "floor")
- {
- isGrounded = true;
- }
- }
- void OnCollisionExit(Collision collision)
- {
- if (collision.gameObject.tag == "floor")
- {
- isGrounded = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement