Advertisement
shadowplaycoding

P001_PlayerController

Apr 7th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerController : MonoBehaviour {
  6.  
  7.     public float Speed = 5;
  8.  
  9.     // Use this for initialization
  10.     void Start () {
  11.        
  12.     }
  13.    
  14.     // Update is called once per frame
  15.     void Update ()
  16.     {
  17.         Move();
  18.     }
  19.  
  20.     void Move()
  21.     {
  22.  
  23.         if (Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0)
  24.         {
  25.             float distance = Speed * Time.deltaTime;
  26.  
  27.             float z = Input.GetAxis("Vertical") * distance;
  28.             float x = Input.GetAxis("Horizontal") * distance;
  29.  
  30.             transform.Translate(x, 0, z);
  31.  
  32.         }
  33.  
  34.     }
  35.  
  36.     /*
  37.     Copyright Shadowplay Coding 2018 - see www.shadowplaycoding.com for licensing details
  38.     Removing this comment forfits any rights given to the user under licensing.
  39.     */
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement