Skip to content

Commit 6a4c349

Browse files
committed
Added FirstPersonFloatingCamera
1 parent 8790f48 commit 6a4c349

File tree

7 files changed

+84
-2
lines changed

7 files changed

+84
-2
lines changed
126 KB
Binary file not shown.

Testie/Assets/main.unity

4.13 KB
Binary file not shown.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
namespace seyahdoo.controlls
6+
{
7+
8+
[AddComponentMenu("Seyahdoo/Controlls/FirstPersonFloatingCamera")]
9+
public class FirstPersonFloatingCamera : MonoBehaviour
10+
{
11+
public bool Working = false;
12+
13+
[Range(0, 5)]
14+
public float Sensivity = 2f;
15+
[Range(0, 2)]
16+
public float MoveSpeed = .2f;
17+
[Range(0, 2)]
18+
public float ShiftSpeedBoost = 1f;
19+
20+
private float _moveSpeed = .2f;
21+
private float _ySpeed = 0;
22+
23+
24+
void Update()
25+
{
26+
//LClick to lock cursor
27+
if (Input.GetMouseButtonDown(0))
28+
{
29+
Cursor.lockState = CursorLockMode.Locked;
30+
Working = true;
31+
}
32+
33+
//If im now workin, there's nothing to do
34+
if (!Working) return;
35+
36+
//ESC to unlock cursor
37+
if (Input.GetKeyDown(KeyCode.Escape))
38+
{
39+
Cursor.lockState = CursorLockMode.None;
40+
Working = false;
41+
}
42+
43+
//LSHIFT to boost
44+
if (Input.GetKey(KeyCode.LeftShift))
45+
_moveSpeed = ShiftSpeedBoost;
46+
else
47+
_moveSpeed = MoveSpeed;
48+
49+
//Handle QE
50+
if (Input.GetKey(KeyCode.Q)) _ySpeed = Mathf.Lerp(_ySpeed, -1, .05f);
51+
else if (Input.GetKey(KeyCode.E)) _ySpeed = Mathf.Lerp(_ySpeed, 1, .05f);
52+
else _ySpeed = Mathf.Lerp(_ySpeed, 0, .1f);
53+
54+
//turn camera
55+
transform.localEulerAngles +=
56+
new Vector3(-Input.GetAxis("Mouse Y"), Input.GetAxis("Mouse X"), 0)
57+
* Sensivity;
58+
59+
//move camera
60+
transform.Translate(
61+
new Vector3(Input.GetAxis("Horizontal"),_ySpeed, Input.GetAxis("Vertical"))
62+
* _moveSpeed);
63+
64+
}
65+
66+
}
67+
68+
}

Testie/Assets/seyahdoo/controlls/FirstPersonFloatingCamera.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Testie/Assets/seyahdoo/controlls/MouseLookSimple.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace seyahdoo.controlls
66
{
7-
7+
[AddComponentMenu("Seyahdoo/Controlls/MouseLookSimple")]
88
public class MouseLookSimple : MonoBehaviour
99
{
1010

Testie/Assets/seyahdoo/crosshair/Crosshair.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020

2121
namespace seyahdoo.crosshair
2222
{
23-
23+
2424
/// <summary>
2525
/// Attach this to a camera, and it will do its stuff
2626
/// </summary>
27+
[AddComponentMenu("Seyahdoo/Crosshair/Crosshair")]
2728
public class Crosshair : MonoBehaviour
2829
{
2930
/// <summary>

Testie/Assets/seyahdoo/crosshair/Target.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace seyahdoo.crosshair
2626
/// Or you can subscribe to FocusOnEvent and FocusOffEvent.
2727
/// You can also derive a class from this and use as such.
2828
/// </summary>
29+
[AddComponentMenu("Seyahdoo/Crosshair/Target")]
2930
[RequireComponent (typeof (Collider))]
3031
public class Target : MonoBehaviour
3132
{

0 commit comments

Comments
 (0)