-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleMoveObject.cs
More file actions
34 lines (24 loc) · 875 Bytes
/
SimpleMoveObject.cs
File metadata and controls
34 lines (24 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
Simple script for moving an object along the X (sides) and Z (forward) directions with the arrow keys + Rotate with Mouse Axis
- Horizontal : X axis : left/right
- Vertical : Z axis : forward/back
This script is ideal for camera controlling
*/
using UnityEngine;
using System.Collections;
public class SimpleMoveObject : MonoBehaviour
{
public int moveSpeed=1;
public int rotSpeed=1;
private float yaw = 0.0f;
private float pitch = 0.0f;
void Update()
{
// Translation along X and Z
transform.Translate(moveSpeed * Input.GetAxis("Horizontal") * Time.deltaTime, 0f, moveSpeed * Input.GetAxis("Vertical") * Time.deltaTime);
//Rotation around X and Y
yaw += rotSpeed * Input.GetAxis("Mouse X");
pitch -= rotSpeed * Input.GetAxis("Mouse Y");
transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
}
}