hurrmmm/godot/CollisionSound.cs

31 lines
554 B
C#
Raw Normal View History

2023-11-12 16:42:00 -07:00
using Godot;
using System;
public partial class CollisionSound : AudioStreamPlayer
{
Node controller;
bool firstPlayed = false;
public override void _Ready()
{
controller = GetNode<Node>("/root/ControllerEventBus");
Callable callable = new Callable(this, MethodName.OnControllerContact);
controller.Connect("new_target", callable);
this.OnControllerContact(this);
}
public void OnControllerContact(Node node)
{
if (firstPlayed) this.Play();
firstPlayed = true;
}
}