diff --git a/Assets/2021-09-01--Probe_no_Tilo-03_Kaputnik.wav b/Assets/2021-09-01--Probe_no_Tilo-03_Kaputnik.wav new file mode 100644 index 0000000000000000000000000000000000000000..b6744aa64abf22b5ca2d8196d0a0d489fce73667 Binary files /dev/null and b/Assets/2021-09-01--Probe_no_Tilo-03_Kaputnik.wav differ diff --git a/Assets/2021-09-01--Probe_no_Tilo-03_Kaputnik.wav.meta b/Assets/2021-09-01--Probe_no_Tilo-03_Kaputnik.wav.meta new file mode 100644 index 0000000000000000000000000000000000000000..4043bf1f56a5f20003e1a765a512c39b917e3d36 --- /dev/null +++ b/Assets/2021-09-01--Probe_no_Tilo-03_Kaputnik.wav.meta @@ -0,0 +1,22 @@ +fileFormatVersion: 2 +guid: 8f96ec519bd0c194fb9d193480403943 +AudioImporter: + externalObjects: {} + serializedVersion: 6 + defaultSettings: + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + preloadAudioData: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Data.cs b/Assets/Data.cs index e7041d3d17b075e73fc579af52f490403e3aff5c..4bd00b73af45e4ecaef7ed1967d4d08b45d00e75 100644 --- a/Assets/Data.cs +++ b/Assets/Data.cs @@ -20,11 +20,11 @@ using UnityEngine.SceneManagement; currentScene = SceneManager.GetActiveScene().name; RegisterScene(currentScene); } - Debug.LogFormat("Current Scene after Awake is: {0}", currentScene); + Debug.LogFormat("[{0}] Current Scene after Awake is: {1}", this.gameObject.name, , currentScene); } public void RegisterSound(string name) { - Debug.LogFormat("Registering Sound as Played: {0}", name); + Debug.LogFormat("[{0}] Registering Sound as Played: {1}", this.gameObject.name, name); PlayedList.Add(name); } @@ -35,7 +35,7 @@ using UnityEngine.SceneManagement; public void UpdateScene(string SceneName){ // Unloading old scene SceneManager.UnloadSceneAsync(currentScene); - Debug.LogFormat("Scene Switch from {0} to {1} completed", currentScene, SceneName); + Debug.LogFormat("[{0}] Scene Switch from {1} to {2} completed", this.gameObject.name, currentScene, SceneName); // Updating new scene currentScene = SceneName; RegisterScene(SceneName); @@ -44,7 +44,7 @@ using UnityEngine.SceneManagement; public void RegisterScene(string name) { if (!WasThereBefore(name)) { VisitedScenes.Add(name); - Debug.LogFormat("Registering Scene as Visited: {0}", name); + Debug.LogFormat("[{0}] Registered Scene as Visited: {1}", this.gameObject.name, name); } } diff --git a/Assets/Movement.cs b/Assets/Movement.cs new file mode 100644 index 0000000000000000000000000000000000000000..da736867b949503fc37d8b251a759b79f46059c5 --- /dev/null +++ b/Assets/Movement.cs @@ -0,0 +1,90 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[RequireComponent(typeof(CharacterController))] +public class Movement : MonoBehaviour +{ + // The Speed at which the Player can move in units per second + [Tooltip("How fast the character moves when walking (units per second).")] + [SerializeField] float moveSpeed = 4f; + + // Allow Jumping + [Tooltip("Should Jumping be allowed?")] + [SerializeField] bool allowJump = true; + + // The height of a jump, in units + [Tooltip("How high should the character jump (in units).")] + [SerializeField] float jumpHeight = 1.5f; + + // The rate at which our vertical speed will be reduced in units per second + [Tooltip("Gravity in units per second.")] + [SerializeField] float gravity = 30f; + + // The degree to which movement can be controlled midair + [Tooltip("How much maneuverability should remain in the air.")] + [Range(0, 10), SerializeField] float airControl = 5; + + // Movement Direction, can be only controlled on the ground + Vector3 moveDirection = Vector3.zero; + + // Reference to the Character Controller (cached) + CharacterController controller; + + // Start is called before the first frame update + void Start() + { + controller = GetComponent<CharacterController>(); + } + + // FixedUpdate must be used if the Player should interact with Physics Objects + void FixedUpdate() + { + // This vector describes the desired plane of movement. If we are in the + // air we will interpolate the current movement with this vector to + // simulate a form of momentum + var input = new Vector3( + Input.GetAxis("Horizontal"), + 0, + Input.GetAxis("Vertical") + ); + + // Multiply the movement with the movement speed + input *= moveSpeed; + + // Convert the rotation to world-space coordinates (as needed by + // the CharacterController Type) + input = transform.TransformDirection(input); + + // Is the Controllers bottom-most point touching the Ground? + if (controller.isGrounded) + { + moveDirection = input; + // If jumping is allowed and the Jump Button is pressed + if (allowJump && Input.GetButton("Jump")) + { + moveDirection.y = Mathf.Sqrt(2 * gravity * jumpHeight); + } + else + { + // Player is on the Ground, cancel Y-Axis Movement + moveDirection.y = 0; + } + } + else + { + // We are falling, so Ignore Y-Axis-Input, but allow user to steer + // the fall on the X/Z-Axis + input.y = moveDirection.y; + moveDirection = Vector3.Lerp(moveDirection, input, airControl * Time.deltaTime); + } + // Subtract the gravity from any Y-Axis movement + moveDirection.y -= gravity * Time.deltaTime; + + // Finally: Move the controller into the desired direction. + // Note: if this would hit a collider or the controller would refuse + // to move further – however – if the other collider would move + // into this object it won't budge.. + controller.Move(moveDirection * Time.deltaTime); + } +} diff --git a/Assets/Movement.cs.meta b/Assets/Movement.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..b8ef9a1becf78a517bbc7c1752d95c635fed3ab4 --- /dev/null +++ b/Assets/Movement.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c34339bcec679b9439d9e65805a5ca72 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index ee265e50449116c89a462cf52a22e33a2e46e213..f7905e1e94815f18f823f6f3bb230805cb9c2b57 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -134,7 +134,7 @@ GameObject: - component: {fileID: 14959384} - component: {fileID: 14959383} m_Layer: 0 - m_Name: Plane + m_Name: Floor m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -213,7 +213,108 @@ Transform: m_LocalScale: {x: 3.7327, y: 3.7327, z: 3.7327} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 2 + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &672941560 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 672941565} + - component: {fileID: 672941564} + - component: {fileID: 672941563} + - component: {fileID: 672941562} + - component: {fileID: 672941561} + m_Layer: 0 + m_Name: player + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!136 &672941561 +CapsuleCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 672941560} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + m_Radius: 0.5 + m_Height: 1 + m_Direction: 1 + m_Center: {x: 0, y: 0, z: 0} +--- !u!114 &672941562 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 672941560} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d3f9dfd0b32f705419e034e2b7fe1fe5, type: 3} + m_Name: + m_EditorClassIdentifier: + mouseSensitivity: {x: 70, y: 60} + smoothing: {x: 2, y: 2} + headUpperAngleLimit: 85 + headLowerAngleLimit: -80 + InvertAxisY: 1 +--- !u!114 &672941563 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 672941560} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c34339bcec679b9439d9e65805a5ca72, type: 3} + m_Name: + m_EditorClassIdentifier: + moveSpeed: 4 + allowJump: 1 + jumpHeight: 1.5 + gravity: 30 + airControl: 5 +--- !u!143 &672941564 +CharacterController: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 672941560} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Height: 2 + m_Radius: 0.5 + m_SlopeLimit: 45 + m_StepOffset: 0.3 + m_SkinWidth: 0.08 + m_MinMoveDistance: 0.001 + m_Center: {x: 0, y: 0, z: 0} +--- !u!4 &672941565 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 672941560} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 963194228} + m_Father: {fileID: 0} + m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &705507993 GameObject: @@ -305,7 +406,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 1 + m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} --- !u!1 &963194225 GameObject: @@ -383,11 +484,11 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 963194225} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 1, z: -10} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 1, z: 0.02} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] - m_Father: {fileID: 0} + m_Father: {fileID: 672941565} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1084437538 @@ -403,8 +504,9 @@ GameObject: - component: {fileID: 1084437541} - component: {fileID: 1084437540} - component: {fileID: 1084437539} + - component: {fileID: 1084437544} m_Layer: 0 - m_Name: Cube + m_Name: AudioTrigger m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -422,13 +524,13 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 24c88adf6dcd2dfd7bc209f1b232bdce, type: 3} m_Name: m_EditorClassIdentifier: - stop_on_exit: 0 - pause_on_exit: 0 - start_on_enter: 1 - start_after_awake: 0 - play_only_once: 0 - start_delay: 0 - stop_delay: 0 + stopOnExit: 0 + pauseOnExit: 1 + startOnEnter: 1 + startAfterAwake: 0 + playOnlyOnce: 0 + startDelay: 0 + stopDelay: 0 --- !u!65 &1084437540 BoxCollider: m_ObjectHideFlags: 0 @@ -437,7 +539,7 @@ BoxCollider: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1084437538} m_Material: {fileID: 0} - m_IsTrigger: 0 + m_IsTrigger: 1 m_Enabled: 1 serializedVersion: 2 m_Size: {x: 1, y: 1, z: 1} @@ -501,5 +603,148 @@ Transform: m_LocalScale: {x: 2.637, y: 1.5812, z: 1.8109} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 3 + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!82 &1084437544 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1084437538} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 0} + m_audioClip: {fileID: 8300000, guid: 8f96ec519bd0c194fb9d193480403943, type: 3} + m_PlayOnAwake: 1 + m_Volume: 1 + m_Pitch: 1 + Loop: 0 + Mute: 0 + Spatialize: 0 + SpatializePostEffects: 0 + Priority: 128 + DopplerLevel: 1 + MinDistance: 1 + MaxDistance: 500 + Pan2D: 0 + rolloffMode: 0 + BypassEffects: 0 + BypassListenerEffects: 0 + BypassReverbZones: 0 + rolloffCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + panLevelCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + spreadCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + reverbZoneMixCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 +--- !u!1 &1969897202 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1969897204} + - component: {fileID: 1969897203} + m_Layer: 0 + m_Name: Data + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1969897203 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1969897202} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ab51f8e0380cd65fab9c074a815c513e, type: 3} + m_Name: + m_EditorClassIdentifier: + debug: 1 + currentScene: SampleScene + PlayedList: [] + VisitedScenes: [] +--- !u!4 &1969897204 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1969897202} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 12.7, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/SmoothMouseLook.cs b/Assets/SmoothMouseLook.cs new file mode 100644 index 0000000000000000000000000000000000000000..bdcf0afc7f8f63ebf4bd3581f074380e6bfd0790 --- /dev/null +++ b/Assets/SmoothMouseLook.cs @@ -0,0 +1,135 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + + +[AddComponentMenu("MouseLook ")] +public class SmoothMouseLook : MonoBehaviour +{ + // The speed at which we turn (Mouse Sensitivity) + // mouseSensitivity.x is for left <-> right + // mouseSensitivity.y is for up <-> down + [Tooltip("How fast to turn when moving the mouse (bigger=faster, X: left<->right, Y: up<->down).")] + [SerializeField] Vector2 mouseSensitivity = new Vector2(70f, 60f); + + // How much smoothing goes on for each axis + [Tooltip("How smooth/mushy the mouse movement becomes (bigger=smoother, X: left<->right, Y: up<->down).")] + [SerializeField] Vector2 smoothing = new Vector2(2f, 2f); + + // How far up the head can tilt, measured in angles from the horizon + // Must be bigger than headLowerAngleLimit + [Tooltip("How many degrees the head can look up at max.")] + [SerializeField] float headUpperAngleLimit = 85f; + + // How far down the head can tilt, measured in angles from the horizon + // Must be smaller than headUpperAngleLimit + [Tooltip("How many degrees the head can look down at max.")] + [SerializeField] float headLowerAngleLimit = -80f; + + // Invert the Y Axis of the Mouse if true + [Tooltip("Invert Mouse Control for up<->down.")] + [SerializeField] bool InvertAxisY = true; + + // Our current rotation from start in degrees + float yaw = 0f; + float pitch = 0f; + + // Stores the orientations of the head and body when the game started + // We'll derive new orientations by combining these with the variables yaw + // and pitch + Quaternion bodyStartOrientation; + Quaternion headStartOrientation; + + // A reference to the head object (the object that will rotate up and down) + // The body is the current (this) object, so there is no variable needed. + // We don't want to expose this to the interface. Instead we just look for a + // Child object with type Camera, when the game starts. + Transform head; + + // Two 2D-Vectors that store both axis of the mouse + private Vector2 smoothedMouseDelta; + + + + // Start is called before the first frame update + void Start() + { + // Find the head – this returns the transform parameter of this objects + // first Child of type Camera. If none is found head = null + head = GetComponentInChildren<Camera>().transform; + + // Cache the orientation of body and head. This errors if head was not + // found + bodyStartOrientation = transform.localRotation; + headStartOrientation = head.transform.localRotation; + + // Lock and hide the cursor + Cursor.lockState = CursorLockMode.Locked; + Cursor.visible = false; + } + + + + // A Easing function that smooths the mouse-movement. This is beeing + // done by making the head follow the mouse not exactly, but + // with some sort of a lag. The further away the heads point of focus + // is compared to the mouse, the faster it will move, once it comes + // closer, it slows down – this is called Easing. + // + // For an intuitive Explaination look here: + // https://processing.org/examples/easing.html + private Vector2 EaseMouseDelta(Vector2 mouseDelta) + { + // Scale input against the sensitivity setting and multiply that + // with the smoothing value. + mouseDelta *= mouseSensitivity.x * smoothing.x * Time.deltaTime; + mouseDelta *= mouseSensitivity.y * smoothing.y * Time.deltaTime; + + // Linear Interpolation ("Lerp") between the smoothed Delta from + // the last round/Frame and the actual mouse Position. + smoothedMouseDelta.x = Mathf.Lerp(smoothedMouseDelta.x, mouseDelta.x, 1f / smoothing.x); + smoothedMouseDelta.y = Mathf.Lerp(smoothedMouseDelta.y, mouseDelta.y, 1f / smoothing.y); + + // Return the smoothed 2D-Vector + return smoothedMouseDelta; + } + + + + // Every time Physics updates, update the movemnent of this object. + // Do this in FixedUpdate to keep pace with physically simulated Objects + void FixedUpdate() + { + // Read the Position-Change between this Frame and the last + // Note: GetRawAxis gives more sensitivity + var mouseDelta = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y")); + + // Run the Smoothing-Function we defined above on the Mouse + // Vector we read before and return a smoothed one + smoothedMouseDelta = EaseMouseDelta(mouseDelta); + + // Flip the vertical Control, if InvertAxisY is true + if (InvertAxisY) + { + smoothedMouseDelta.y *= -1; + } + + // Add the mouse movements to the current value of yaw and pitch + yaw += smoothedMouseDelta.x; + pitch += smoothedMouseDelta.y; + + // Clamp pitch so that we can't look directly down or up + pitch = Mathf.Clamp(pitch, headLowerAngleLimit, headUpperAngleLimit); + + // Compute rotations by rotating around a fixed axis (rotate yaw-degrees + // around the up direction for the body, and pitch degrees around the + // right direction for the head). + // Note: 90 deg need to be added, to get the initial orientation right + var bodyRotation = Quaternion.AngleAxis(yaw + 90, Vector3.up); + var headRotation = Quaternion.AngleAxis(pitch, Vector3.right); + + // Finally combine the rotations for body and head with the start rotations + transform.localRotation = bodyRotation * bodyStartOrientation; + head.localRotation = headRotation * headStartOrientation; + } +} diff --git a/Assets/SmoothMouseLook.cs.meta b/Assets/SmoothMouseLook.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..d9cf406c96f5f03e18cc76f132d441585a0a5757 --- /dev/null +++ b/Assets/SmoothMouseLook.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d3f9dfd0b32f705419e034e2b7fe1fe5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/SoundManager.cs b/Assets/SoundManager.cs index 831b5d8bd487c93fdb044bfd13e523ad82ccf14e..32167873ff4e63318684c721b11aba8dafc60248 100644 --- a/Assets/SoundManager.cs +++ b/Assets/SoundManager.cs @@ -6,7 +6,8 @@ using System; [RequireComponent(typeof(AudioSource))] [RequireComponent(typeof(Collider))] public class SoundManager : MonoBehaviour -{ +{ + public GameObject player; public Boolean stopOnExit = false; public Boolean pauseOnExit = false; public Boolean startOnEnter = true; @@ -31,26 +32,33 @@ public class SoundManager : MonoBehaviour void OnTriggerEnter(Collider other) { - if (startOnEnter) + if (startOnEnter && other.gameObject.name == player.name) { // Start sound only if we want to "restart on enter" // Otherwise only start it, if it isn't playing already if (never_played_before || !source.isPlaying) { Invoke("Play", startDelay); + Debug.LogFormat("[{0}] Started playing sound because of collision with {1}", this.gameObject.name, other.gameObject.name); } } + else if (!startOnEnter) + { + Debug.LogFormat("[{0}] Collided with {1} but didn't trigger sound because it wasnt {2}", this.gameObject.name, other.gameObject.name, player.name); + } } void OnTriggerExit(Collider other) { - if (stopOnExit) + if (stopOnExit && other.gameObject.name == player.name) { Invoke("Stop", stopDelay); + Debug.LogFormat("[{0}] Stopped sound because {1} exited collider", this.gameObject.name, other.gameObject.name); } - else if (pauseOnExit) + else if (pauseOnExit && other.gameObject.name == player.name) { Invoke("Pause", stopDelay); + Debug.LogFormat("[{0}] Paused sound because {1} exited collider", this.gameObject.name, other.gameObject.name); } } @@ -61,11 +69,11 @@ public class SoundManager : MonoBehaviour source.Play(); never_played_before = false; Data.instance.RegisterSound(source.name); - }else { Debug.LogFormat("Didn't play sound again: {0}", source.name); } + }else { Debug.LogFormat("[{0}] Didn't play sound again: {1}", this.gameObject.name, source.name); } }else{ source.Play(); never_played_before = false; - Debug.LogFormat("Registered as Played: {0}", source.name); + Debug.LogFormat("[{0}] Registered as Played: {1}", this.gameObject.name, source.name); Data.instance.RegisterSound(source.name); } } diff --git a/Data.cs b/Data.cs deleted file mode 100644 index e7041d3d17b075e73fc579af52f490403e3aff5c..0000000000000000000000000000000000000000 --- a/Data.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.SceneManagement; - - public class Data : MonoBehaviour - { - public bool debug = true; - public static Data instance; - public string currentScene; - public List<string> PlayedList = new List<string>(); - public List<string> VisitedScenes = new List<string>(); - - void Awake() { - if(instance == null) { - instance = this; - DontDestroyOnLoad(this.gameObject); - } - if (currentScene == "") { - currentScene = SceneManager.GetActiveScene().name; - RegisterScene(currentScene); - } - Debug.LogFormat("Current Scene after Awake is: {0}", currentScene); - } - - public void RegisterSound(string name) { - Debug.LogFormat("Registering Sound as Played: {0}", name); - PlayedList.Add(name); - } - - public bool PlayedSound(string name) { - return PlayedList.Contains(name); - } - - public void UpdateScene(string SceneName){ - // Unloading old scene - SceneManager.UnloadSceneAsync(currentScene); - Debug.LogFormat("Scene Switch from {0} to {1} completed", currentScene, SceneName); - // Updating new scene - currentScene = SceneName; - RegisterScene(SceneName); - } - - public void RegisterScene(string name) { - if (!WasThereBefore(name)) { - VisitedScenes.Add(name); - Debug.LogFormat("Registering Scene as Visited: {0}", name); - } - } - - // Return true if the scene was visited before - public bool WasThereBefore(string name) { - return VisitedScenes.Contains(name); - } - - // Return true if the current scene was visited before - public bool WasHereBefore() { - return VisitedScenes.Contains(currentScene); - } - -} diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index 0147887ef4b113c3a3b8da44ef30e3208f1e9120..40917b058da46ff0f4816cb68f7a6192028b3aad 100644 --- a/ProjectSettings/EditorBuildSettings.asset +++ b/ProjectSettings/EditorBuildSettings.asset @@ -4,5 +4,8 @@ EditorBuildSettings: m_ObjectHideFlags: 0 serializedVersion: 2 - m_Scenes: [] + m_Scenes: + - enabled: 1 + path: Assets/Scenes/SampleScene.unity + guid: 9fc0d4010bbf28b4594072e72b8655ab m_configObjects: {}