This seems like something that should be a very straightforward fix but I am very new to scripting. I am using the asset Surface Waves. To initiate a wave, the input intensity needs to go from 0 to a positive number. I have it set up so that when I press space, the wave is initiated using this script:
So the wave is initiated, then the value goes back down to 0 and it works. I would like to be able to click a UI button to initiate the wave but I don’t know how to get that input in place of the getbuttondown element. I know how to use the OnClick part of the UI buttons but I don’t understand what kind of function I should use to trigger this.
Thanks!
On your UI Button you need to add a new “On Click()” event by pressing the + sign.
Inside your script your WaveSource create a new function.
public void ButtonClick()
{
//Do whatever you want here
}
On your button, drag the game object containing your WaveSource script into the empty area asking for a game object. Click the “No Function” drop down, find WaveSource, expand and find “ButtonClick()”
Now when you click the button while the game is running it will call the “ButtonClick()” function inside your WaveSource script. Add whatever you want to the “ButtonClick()” function.
public void ButtonClick()
{
source.inputIntensity = .01f;
}
If you want the value to instantly be set back to 0.0 and you never want that button to work after, you can implement a bool check. You can do something like this.
bool firstSetup = false;
// Use this for initialization
void Start () {
}
void Update()
{
if (source.inputIntensity > 0.0f && !firstSetup)
{
firstSetup = true;
source.inputIntensity = 0.0f;
}
}
public void ButtonClick()
{
if (!firstSetup)
{
source.inputIntensity = .01f;
}
}
This will work in a similar way to GetButtonDown or GetButtonUp, but it will not work the same as GetButton.