Light switch with spatial sound

Light switch with spatial sound

Create a OmniLight and a MeshInstance  for the light switch in a scene.

Add a collidable MeshInstance so that ray emitted from the player's FPS camera can be used to interact with it.

Add a SpatialSamplePlayer to LightSwitch1 and populate it with a sound.

Name the instances as follows:

OmniLight = OmniLight1

MeshInstance = LightSwitch1

Add U_ in the name of the MeshInstance collider node, e.g U_col

Add the following script to LightSwitch1:

LightSwitch1

extends StaticBody

var game

func _ready:

game = get_node( "/root/Game" )

func use( leftUse, rightUse):

var light = get_node( "/root/Main/OmniLight1" )

if( light.is_enabled ):

game.sendString( "OmniLight1", "Off" )

else:

game.sendString( "OmniLight1", "On" )

Add the following script to OmniLight1:

OmniLight1

extends OmniLight

var game

func _ready:

game = get_node( "/root/Game" )

game.initString( "OmniLight1", "On")

func receiveString( data ):

if( data=="Off" ):

set_enabled( false )

else:

set_enabled( true )

get_node("/root/Main/LightSwitch1/SpatialSamplePlayer").play( "Switch1" )

func initString( data  ):

if( data=="Off" ):

set_enabled( false )

else:

set_enabled( true )