Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerController : MonoBehaviour {
- public float speed = 3.0f;
- private Vector3 pos;
- // Use this for initialization
- void Start () {
- pos = transform.position;
- }
- // Update is called once per frame
- void FixedUpdate () {
- if(Input.GetKey(KeyCode.LeftArrow) && transform.position == pos) {
- pos += Vector3.left;
- }
- if(Input.GetKey(KeyCode.RightArrow) && transform.position == pos) {
- pos += Vector3.right;
- }
- if(Input.GetKey(KeyCode.UpArrow) && transform.position == pos) {
- pos += Vector3.up;
- }
- if(Input.GetKey(KeyCode.DownArrow) && transform.position == pos) {
- pos += Vector3.down;
- }
- transform.position = Vector3.MoveTowards(transform.position, pos, Time.deltaTime * speed);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement