- Home /
Convert "SHIFT" button for running to Mobile?
I have this script (courtesy of Alucardj) and it is a script for running and playing the footstep sounds. Now since I am trying to apply this script (which is for PC) into my Android game, how will I be able to convert the "hold the shift button to run" mechanic, into "hold the right touch pad to run"?
Here is the portion of the script:
function SetSpeed()
{
var speed = walkSpeed;
if ( chCtrl.isGrounded && Input.GetKey("left shift") || Input.GetKey("right shift") )
{
speed = runSpeed;
}
chMotor.movement.maxForwardSpeed = speed;
}
function PlayFootsteps()
{
if ( Input.GetAxis( "Horizontal" ) || Input.GetAxis( "Vertical" ) )
{
if ( Input.GetKey( "left shift" ) || Input.GetKey( "right shift" ) )
{
// Running
isWalking = false;
isRunning = true;
}
else
{
// Walking
isWalking = true;
isRunning = false;
}
}
else
{
// Stopped
isWalking = false;
isRunning = false;
}
Answer by yogee · Oct 19, 2013 at 06:04 AM
http://docs.unity3d.com/Documentation/ScriptReference/TouchPhase.Stationary.html
this link ll help u
Alright, this has activated the running (finally!) which is great. Thank you for the link.
The only problem now is that the character is now always running, because my finger is of course stationary when I am leaving my finger on the screen for the direction of the character movement. How would I approach this issue? :)
I need my finger to be on the touch screen in order to make the character move, and for which direction my character will walk with where my finger is at. Since my finger will always need to on the screen, touchphase.stationary will always be applied to the game, do I will always be running.
I'm thinking if a possible way to solve this would be to have a separate GUIButton on the screen used just for running. Basically a running button with a little stick figure in a running stance in it. :)
if(TouchPhase.Began ) { //walk // u can move ur finger while moving it won't affect the movement //until u release ur finger (TouchPhase.Ended) } else if(TouchPhase.Ended) { //end of walk //i.e, release of ur finger }