Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Assets/Art/Prefabs/House.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -13297,7 +13297,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
keysRequiredToTrigger: 1
soundToPlay: 4
soundType: 4
--- !u!1 &7927258282318190006
GameObject:
m_ObjectHideFlags: 0
Expand Down
71 changes: 1 addition & 70 deletions Assets/Scenes/GameScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -2228,30 +2228,6 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 667724600942481522, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
propertyPath: soundService
value:
objectReference: {fileID: 203687011}
- target: {fileID: 2005042993226810447, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
propertyPath: soundService
value:
objectReference: {fileID: 203687011}
- target: {fileID: 2196900891731812331, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
propertyPath: soundService
value:
objectReference: {fileID: 203687011}
- target: {fileID: 3492344741786150290, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
propertyPath: gameUIView
value:
objectReference: {fileID: 2132082659}
- target: {fileID: 3492344741786150290, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
propertyPath: soundService
value:
objectReference: {fileID: 203687011}
- target: {fileID: 3542250534102899431, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
propertyPath: soundService
value:
objectReference: {fileID: 203687011}
- target: {fileID: 5325831579243014017, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
propertyPath: m_RootOrder
value: 0
Expand Down Expand Up @@ -2296,56 +2272,11 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6752750673420198879, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
propertyPath: soundService
value:
objectReference: {fileID: 203687011}
- target: {fileID: 6752750673610657977, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
propertyPath: soundService
value:
objectReference: {fileID: 203687011}
- target: {fileID: 6752750674094668609, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
propertyPath: soundService
value:
objectReference: {fileID: 203687011}
- target: {fileID: 8090694453975587124, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
propertyPath: m_Name
value: House
objectReference: {fileID: 0}
- target: {fileID: 8410985323073775251, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
propertyPath: soundService
value:
objectReference: {fileID: 203687011}
- target: {fileID: 8410985323525627662, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
propertyPath: soundService
value:
objectReference: {fileID: 203687011}
- target: {fileID: 8410985323951209738, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
propertyPath: soundService
value:
objectReference: {fileID: 203687011}
- target: {fileID: 8410985324532678281, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
propertyPath: soundService
value:
objectReference: {fileID: 203687011}
- target: {fileID: 8410985324693255829, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
propertyPath: soundService
value:
objectReference: {fileID: 203687011}
- target: {fileID: 8410985324735834856, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
propertyPath: soundService
value:
objectReference: {fileID: 203687011}
- target: {fileID: 8410985324760981946, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
propertyPath: soundService
value:
objectReference: {fileID: 203687011}
m_RemovedComponents:
- {fileID: 8410985324760981946, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
- {fileID: 6752750673610657977, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
- {fileID: 8410985324735834856, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
- {fileID: 3542250534102899431, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
- {fileID: 6752750674094668609, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: d2470b45bfcea9e4780d1866d7cd0f8c, type: 3}
--- !u!65 &8225950124344110251
BoxCollider:
Expand Down
12 changes: 12 additions & 0 deletions Assets/Scripts/Events/LightsOffByGhostEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,17 @@

public class LightsOffByGhostEvent : MonoBehaviour
{
[SerializeField] private int keysRequiredToTrigger;
[SerializeField] private SoundType soundType;

private void OnTriggerEnter(Collider other)
{
if(other.GetComponent<PlayerView>() != null && keysRequiredToTrigger == GameService.Instance.GetPlayerController().KeysEquipped)
{
EventService.Instance.OnLightsOffByGhostEvent.InvokeEvent();
GameService.Instance.GetSoundView().PlaySoundEffects(soundType);
this.enabled = false;
}
}

}
32 changes: 30 additions & 2 deletions Assets/Scripts/Interactables/LightSwitchView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ public class LightSwitchView : MonoBehaviour, IInteractable
[SerializeField] private List<Light> lightsources = new List<Light>();
private SwitchState currentState;

private void OnEnable() => EventService.Instance.OnLightSwitchToggled.AddListener(onLightSwitch);
private void OnEnable()
{
EventService.Instance.OnLightSwitchToggled.AddListener(onLightSwitch);
EventService.Instance.OnLightsOffByGhostEvent.AddListener(onLightTurnedOffByGhost);
}

private void OnDisable() => EventService.Instance.OnLightSwitchToggled.RemoveListener(onLightSwitch);
private void OnDisable()
{
EventService.Instance.OnLightSwitchToggled.RemoveListener(onLightSwitch);
EventService.Instance.OnLightsOffByGhostEvent.RemoveListener(onLightTurnedOffByGhost);
}

private void Start() => currentState = SwitchState.Off;

Expand Down Expand Up @@ -39,10 +47,30 @@ private void toggleLights()
}
}

private void setLights(bool lights)
{
foreach (Light lightSource in lightsources)
{
lightSource.enabled = lights;
}

if (lights)
currentState = SwitchState.On;
else
currentState = SwitchState.Off;
}

private void onLightSwitch()
{
toggleLights();
GameService.Instance.GetSoundView().PlaySoundEffects(SoundType.SwitchSound);
GameService.Instance.GetInstructionView().HideInstruction();
}

private void onLightTurnedOffByGhost()
{
setLights(false);
GameService.Instance.GetSoundView().PlaySoundEffects(SoundType.SwitchSound);
GameService.Instance.GetInstructionView().ShowInstruction(InstructionType.LightsOff);
}
}
5 changes: 5 additions & 0 deletions Assets/Scripts/Player/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ public PlayerController(PlayerView playerView, PlayerScriptableObject playerScri
playerState = PlayerState.InDark;

EventService.Instance.OnLightSwitchToggled.AddListener(onLightSwitch);
EventService.Instance.OnLightsOffByGhostEvent.AddListener(onLightsTurnedOffByGhost);
EventService.Instance.OnKeyPickedUp.AddListener(onKeysPickedUp);
}

~PlayerController()
{
EventService.Instance.OnLightSwitchToggled.RemoveListener(onLightSwitch);
EventService.Instance.OnLightsOffByGhostEvent.RemoveListener(onLightsTurnedOffByGhost);
EventService.Instance.OnKeyPickedUp.RemoveListener(onKeysPickedUp);
}
public void Interact() => IsInteracted = Input.GetKeyDown(KeyCode.E) ? true : (Input.GetKeyUp(KeyCode.E) ? false : IsInteracted);
Expand Down Expand Up @@ -87,6 +89,9 @@ private void onLightSwitch()
else
PlayerState = PlayerState.InDark;
}

private void onLightsTurnedOffByGhost() => PlayerState = PlayerState.InDark;

private void onKeysPickedUp(int keys)
{
KeysEquipped = keys;
Expand Down