-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMove.cs
24 lines (20 loc) · 871 Bytes
/
Move.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Move : MonoBehaviour {
public float speed = 5;
//Keep a reference to our rigidbody
private Rigidbody rb;
void Start () { //called when object is created
rb = GetComponent<Rigidbody>(); //finds the rigidbody component in this object
}
void Update () {//called every frame of the game
rb.MovePosition(transform.position +
new Vector3(Input.GetAxis("Horizontal"),
Input.GetAxis("Vertical"),
0) * speed * Time.deltaTime);
// rb.MovePosition(transform.position +
// (Vector3.right * Input.GetAxis("Horizontal") +
// Vector3.up * Input.GetAxis("Vertical")) * speed * Time.deltaTime);
}
}