To convert a negative number to a positive number, use the Abs function. Like this.
int myInt = System.Math.Abs(-5);
To convert a positive number to a negative number there is no built in function, but you can simply do this,
myInt = myInt * -1
Here’s a simple way to play a sound in Unity.
1. Add something like this to the declaration section of your script.
public AudioSource audioSourceExplosion;
2. Add this line of code where you want to play the sound.
3. NOTE : What I have called audioSourceExplosion here is the name of the variable and of course must match at step one and two.
4. Add an Audio Source component to the GameObject your script is attached to in the Hierarchy.
5. Attach you sound to the new Audio Component.
5. A public variable should have appeared on your GameObject, drag the Audio Source component onto this variable.
The template files for Unity’s scripts are kept in
The new behaviour script, the most common one is called (or something similar, depending on version)