Skip to content

Commit

Permalink
mouse control added: rotate cam, zoom in/out, WASD
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLissandra1 committed Apr 11, 2023
1 parent 421c522 commit 463cf0b
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 2 deletions.
17 changes: 16 additions & 1 deletion Assets/Scenes/Collision.unity
Original file line number Diff line number Diff line change
Expand Up @@ -628,10 +628,11 @@ GameObject:
- component: {fileID: 1733875309}
- component: {fileID: 1733875308}
- component: {fileID: 1733875307}
- component: {fileID: 1733875312}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_Icon: {fileID: 3936346786652291628, guid: 0000000000000000d000000000000000, type: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
Expand Down Expand Up @@ -701,3 +702,17 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1733875312
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1733875306}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: acccb294b11d14f40a005cc61d590f6e, type: 3}
m_Name:
m_EditorClassIdentifier:
sensitivity: 2
cam: {fileID: 1733875308}
17 changes: 16 additions & 1 deletion Assets/Scenes/FlagAndWind.unity
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,11 @@ GameObject:
- component: {fileID: 1733875309}
- component: {fileID: 1733875308}
- component: {fileID: 1733875307}
- component: {fileID: 1733875310}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_Icon: {fileID: 3936346786652291628, guid: 0000000000000000d000000000000000, type: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
Expand Down Expand Up @@ -603,3 +604,17 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1733875310
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1733875306}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: acccb294b11d14f40a005cc61d590f6e, type: 3}
m_Name:
m_EditorClassIdentifier:
sensitivity: 2
cam: {fileID: 1733875308}
15 changes: 15 additions & 0 deletions Assets/Scenes/Plastic.unity
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ GameObject:
- component: {fileID: 1733875309}
- component: {fileID: 1733875308}
- component: {fileID: 1733875307}
- component: {fileID: 1733875310}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
Expand Down Expand Up @@ -603,3 +604,17 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1733875310
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1733875306}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: acccb294b11d14f40a005cc61d590f6e, type: 3}
m_Name:
m_EditorClassIdentifier:
sensitivity: 2
cam: {fileID: 0}
50 changes: 50 additions & 0 deletions Assets/Scripts/MouseLookAround.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MouseLookAround : MonoBehaviour
{
// // Start is called before the first frame update
// void Start()
// {

// }
float rotationX = 0f;
float rotationY = 0f;
public float sensitivity = 2f;
float moveSpeed = 10f;

public Camera cam;
// Update is called once per frame
void Update()
{
rotationY += Input.GetAxis("Mouse X") * sensitivity;
rotationX += Input.GetAxis("Mouse Y") * -1 * sensitivity;
transform.localEulerAngles = new Vector3(rotationX,rotationY,0);

// WASD/Arrows: move cam
transform.position += transform.forward * moveSpeed * Input.GetAxisRaw("Vertical") * Time.deltaTime;
transform.position += transform.right * moveSpeed * Input.GetAxisRaw("Horizontal") * Time.deltaTime;

// Zoom out Camera with Mouse Scroll Wheel
if (Input.GetAxis("Mouse ScrollWheel") < 0)
{
if (cam.fieldOfView <= 100)
cam.fieldOfView += 2;
if (cam.orthographicSize <= 20)
cam.orthographicSize += 0.5F;
}
// Zoom in
if (Input.GetAxis("Mouse ScrollWheel") > 0)
{
if (cam.fieldOfView > 2)
cam.fieldOfView -= 2;
if (cam.orthographicSize >= 1)
cam.orthographicSize -= 0.5F;
}

}

}


0 comments on commit 463cf0b

Please sign in to comment.