Park/Events/EventEffects/RainEvent.cs
using HC3;
public class RainEvent : BaseEvent
{
[Property] GameObject RainObject { get; set; } = null;
[Property] SoundEvent RainSound { get; set; }
GameObject CameraObject { get; set; }
private SoundHandle _sound;
private List<Guest> AllGuests;
protected override void OnStart()
{
base.OnStart();
AllGuests = Scene.GetAllComponents<Guest>().ToList();
CameraObject = Scene.Camera.GameObject;
_sound = Sound.Play( RainSound );
}
protected override void OnUpdate()
{
base.OnUpdate();
if ( !CameraObject.IsValid() ) return;
if ( !RainObject.IsValid() ) return;
RainObject.WorldPosition = CameraObject.WorldPosition + new Vector3( 0, 0, 100 ) + CameraObject.WorldRotation.Forward * 50;
_sound.Paused = DayNightController.Instance.IsPaused;
// Don't update guests happiness if we aren't the host.
if ( !Networking.IsHost )
return;
if ( AllGuests == null ) return;
foreach ( var guest in AllGuests )
{
if ( guest.IsValid() )
{
guest.Needs.Happiness -= Time.Delta * 0.002f;
}
}
}
protected override void OnDestroy()
{
_sound?.Stop();
}
}