Scripting in Unity - Parameter controlled by player inputs + referencing event emitter out of script

Hi there,

I am a composer and am very new to using C# and Unity. I am currently working on a project for a client and am need of assistance writing a script for a particular command I had in mind.

The player is controlled using arrow keys and WASD. I am attempting to write a script that controls a custom parameter depending on when the input of any of the buttons is engaged or not.

Here is my script I’ve been working on:

I attached the script to the game object that has the studio event emitter.

The error message I’m getting underneath the Input.GetAxis line says that the ‘comparison of floating point numbers can be unequal due to the differing precision of the two values’, which I’m not too sure what that means…

I’m finding that having my custom script start my event instead of the stock FMOD ‘event emitter’ is ruining the spatialisation of the event. Everything within that event becomes mono, which isn’t an issue when my script is inactive and the event emitter triggers the event.

Is there any way to just reference the event emitter script within my MoveFX script?

This seems like it would be a minimal, straight forward script.

If anyone is able to help me out and point me in the right direction towards a coherent script, that would be much appreciated.


  • Tom

This is more of a Unity question but the error you are seeing is saying you have a condition saying if the Input.GetAxis("Horizontal") is exactly 1, then set the parameter to this value. The problem the error message is telling you is Input.GetAxis returns a float which is a decimal. Unless the horizontal axis is exactly all the way to the left/right, this condition won’t be met. Imagine that Input.GetAxis is getting the coordinates for the location of the analogue stick. It would be better to check if the input is not 0 (eg. it is being pushed in either direction) such as Input.GetAxis("Horizontal") != 0

In terms of getting the reference to the event emitter, whilst you can do this, it might be cleaner to have the event setup in the movement script you have. You mention the event becoming mono, am I right in thinking this event is meant to be 3D? In that case you can use this Unity helper function to attach the event to a game object.

Hi Richard,

Thank you very much for your advice.

My script currently looks like this. I updated it so the FMOD event gets triggered within my script:

I am trying to figure it out where to place the AttachInstanceToGameObject function but am having trouble…visual studio won’t recognise it as a proper function. Whereabouts would I place this within my script?

I have since discovered since we last spoke that the event doesn’t become ‘mono’ per se, more that the spatialisation placement becomes incorrect. Instead of the audio being perceptively in front of the player with a stereo spread, the audio gets panned hard left and is flipped 90 degrees. So not so much ‘mono’ as it is just flipped the wrong way around…

I get a warning within Unity that the script hasn’t had 3D attributes set to it yet, which I’m guessing is why I’m having this problem.

Any suggestions would be a great help.


So the script that you have has the suggestions to say that it would be unlikely to meet those conditions, at least easily. Basically the GetAxis("Horizontal") and GetAxis("Vertical") are the X and Y axis on the analogue sticks. As mentioned, for the axis to be 1.0f would be for the stick to be perfectly left/right or perfectly up/down, so instead checking if it’s not 0.0f is better.

You can use FMODUnity.RuntimeManager.AttachInstanceToGameObject(MainEvent, gameObject.transform, gameObject.GetComponent<Rigidbody>()); in your Start() function before starting the instance (line 21).

It sounds like the event instance might be placed in the exact same location as the listener which could be troublesome. If the attached event instance is having the same issue, then you can try having an empty gameobject directly in front of the listener and attach the event instance to that.