Time for action – creating an interactive button
Now that you've created a cannon prefab, we can start writing scripts for it that use the OUYA controller's touchpad. The first functionality we'll add is an interactive button that makes the cannon fire a cannonball when it's tapped. Perform the following steps to add an interactive button:
Create a new script named
CannonScript.cs
in yourCode
folder and attach it to yourCannon
prefab.Open
CannonScript.cs
in your code editor.Declare the following variables at the top of the
CannonScript
class definition, just before theStart
function:private int buttonWidth; private int buttonHeight; private string buttonText; void Start() { }
Initialize each variable with values for our new button in the
Start
function. Give the button a width of100
, a height of50
, and a"Fire!"
text label, as shown in the following code:Private int buttonWidth; private int buttonHeight; private string buttonText; Void Start() { buttonWidth = 100; buttonHeight...