Compare commits
2 Commits
0fe59fd1e3
...
73321b98cd
| Author | SHA1 | Date | |
|---|---|---|---|
| 73321b98cd | |||
| 0b266784fb |
+27
-17
@@ -5,8 +5,8 @@ using System.Collections;
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class CameraVehicle : MonoBehaviour
|
public class CameraVehicle : MonoBehaviour
|
||||||
{
|
{
|
||||||
public float sensitivityX = 20F;
|
public float sensitivityX = 45F;
|
||||||
public float sensitivityY = 20F;
|
public float sensitivityY = 45F;
|
||||||
|
|
||||||
public float minimumX = -360F;
|
public float minimumX = -360F;
|
||||||
public float maximumX = 360F;
|
public float maximumX = 360F;
|
||||||
@@ -14,31 +14,29 @@ public class CameraVehicle : MonoBehaviour
|
|||||||
public float minimumY = -90F;
|
public float minimumY = -90F;
|
||||||
public float maximumY = 90F;
|
public float maximumY = 90F;
|
||||||
|
|
||||||
public float moveSpeed = 0.25f;
|
public float moveSpeed = 0.125f;
|
||||||
|
|
||||||
float rotationX = 0F;
|
float rotationX = 0F;
|
||||||
float rotationY = 0F;
|
float rotationY = 0F;
|
||||||
|
|
||||||
Quaternion originalRotation;
|
Quaternion originalRotation;
|
||||||
|
|
||||||
|
bool moveCam = false;
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
if(Input.GetKeyDown(KeyCode.LeftAlt) && Screen.lockCursor == false)
|
moveCam = Input.GetKey(KeyCode.LeftAlt);
|
||||||
{
|
|
||||||
Screen.showCursor = false;
|
if(!moveCam)
|
||||||
Screen.lockCursor = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(Input.GetKeyDown(KeyCode.Escape))
|
|
||||||
{
|
{
|
||||||
Screen.lockCursor = false;
|
Screen.lockCursor = false;
|
||||||
Screen.showCursor = true;
|
Screen.showCursor = true;
|
||||||
}
|
|
||||||
if(Screen.lockCursor == false)
|
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Screen.showCursor = false;
|
||||||
|
Screen.lockCursor = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
|
rotationX += Input.GetAxis("Mouse X") * sensitivityX;
|
||||||
@@ -52,6 +50,17 @@ public class CameraVehicle : MonoBehaviour
|
|||||||
|
|
||||||
transform.localRotation = originalRotation * xQuaternion * yQuaternion;
|
transform.localRotation = originalRotation * xQuaternion * yQuaternion;
|
||||||
|
|
||||||
|
if(Input.GetKeyDown(KeyCode.R))
|
||||||
|
{
|
||||||
|
transform.localEulerAngles = Vector3.zero;
|
||||||
|
transform.position = Vector3.zero;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FixedUpdate()
|
||||||
|
{
|
||||||
|
if(!moveCam) return;
|
||||||
|
|
||||||
Vector3 pos = transform.position;
|
Vector3 pos = transform.position;
|
||||||
Vector3 direction = Vector3.zero;
|
Vector3 direction = Vector3.zero;
|
||||||
if(Input.GetKey(KeyCode.W))
|
if(Input.GetKey(KeyCode.W))
|
||||||
@@ -70,11 +79,11 @@ public class CameraVehicle : MonoBehaviour
|
|||||||
{
|
{
|
||||||
direction += Vector3.left;
|
direction += Vector3.left;
|
||||||
}
|
}
|
||||||
if(Input.GetKey(KeyCode.Space))
|
if(Input.GetKey(KeyCode.E))
|
||||||
{
|
{
|
||||||
direction += Vector3.up;
|
direction += Vector3.up;
|
||||||
}
|
}
|
||||||
if(Input.GetKey(KeyCode.LeftShift))
|
if(Input.GetKey(KeyCode.Q))
|
||||||
{
|
{
|
||||||
direction += Vector3.down;
|
direction += Vector3.down;
|
||||||
}
|
}
|
||||||
@@ -82,7 +91,8 @@ public class CameraVehicle : MonoBehaviour
|
|||||||
{
|
{
|
||||||
direction *= 2;
|
direction *= 2;
|
||||||
}
|
}
|
||||||
pos += transform.rotation * direction * moveSpeed;
|
Quaternion movrot = Quaternion.Euler(0f, transform.localEulerAngles.y, 0f);
|
||||||
|
pos += movrot * direction * moveSpeed;
|
||||||
transform.position = pos;
|
transform.position = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user