hurrmmm/godot/CollisionSound.cs

31 lines
554 B
C#

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;
}
}