Advertisement
Guest User

Untitled

a guest
Jun 21st, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 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 = 3.0f;
  8.     private Vector3 pos;
  9.  
  10.     // Use this for initialization
  11.     void Start () {
  12.         pos = transform.position;
  13.     }
  14.    
  15.     // Update is called once per frame
  16.     void FixedUpdate () {
  17.          if(Input.GetKey(KeyCode.LeftArrow) && transform.position == pos) {
  18.              pos += Vector3.left;
  19.          }
  20.          if(Input.GetKey(KeyCode.RightArrow) && transform.position == pos) {
  21.              pos += Vector3.right;
  22.          }
  23.          if(Input.GetKey(KeyCode.UpArrow) && transform.position == pos) {
  24.              pos += Vector3.up;
  25.          }
  26.          if(Input.GetKey(KeyCode.DownArrow) && transform.position == pos) {
  27.              pos += Vector3.down;
  28.          }
  29.          transform.position = Vector3.MoveTowards(transform.position, pos, Time.deltaTime * speed);
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement