36 lines
918 B
C#
36 lines
918 B
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
public class PlayerMovement : MonoBehaviour {
|
|||
|
Rigidbody rb;
|
|||
|
public float speed = 10f;
|
|||
|
public bool active = true;
|
|||
|
|
|||
|
void Start () {
|
|||
|
rb = GetComponent<Rigidbody>();
|
|||
|
}
|
|||
|
|
|||
|
void Update () {
|
|||
|
if( active )
|
|||
|
{
|
|||
|
if (Input.GetKey(KeyCode.UpArrow))
|
|||
|
{
|
|||
|
rb.AddForce(new Vector3(1, 0, 0) * speed);
|
|||
|
}
|
|||
|
if (Input.GetKey(KeyCode.DownArrow))
|
|||
|
{
|
|||
|
rb.AddForce(new Vector3(-1, 0, 0) * speed);
|
|||
|
}
|
|||
|
if (Input.GetKey(KeyCode.LeftArrow))
|
|||
|
{
|
|||
|
rb.AddForce(new Vector3(0, 0, 1) * speed);
|
|||
|
}
|
|||
|
if (Input.GetKey(KeyCode.RightArrow))
|
|||
|
{
|
|||
|
rb.AddForce(new Vector3(0, 0, -1) * speed);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|