So I was adding my buttons to the game
using UI event sytem in Unity.
The Fire and Flip where easy but when it
came to the Thrust button I hit a snag. The button click is not enough I need
it to respond when the button stays pressed.
To do this I needed to add Event Trigger
component to the button.
Then in the component click add new event
type for Pointer Down and Pointer Up.
Here is the code for the 2 functions:
public void
ThrustDown()
{
IsThrust = true;
}
public void
ThrustUp()
{
IsThrust = false;
}
Then in the FixedUpdate() check if IsThrust
then increase the speed, also I’ve added the code to slow down the player over
time with the Speed *
.99f:
if
(IsThrust)
{
Speed +=
thrustAmount;
if (Speed
> MaxSpeed)
Speed = MaxSpeed;
}
Speed = Speed * .99f;
No comments:
Post a Comment