Player movement issue

Hey guys ok so i have GUITextures set to move my player for my mobile game here is my code

void MoveLeft () 
	{
		transform.position += moveSpeed * movementDirectionLeft * Time.deltaTime;					
	}
	
	void MoveRight()
	{
		
		transform.position += moveSpeed * movementDirectionRight * Time.deltaTime;

can someone shed some light on why when GUItexture is touched the “Player” only moves once per hit versus moving constantly as long as GUItexture is pressed thanks for anyone helps my first game using mobile touchscreen so still wrapping my head around it oh and here the code for Hit-test

if(Input.touches.Length <= 0)
		{
			//if no touches then will execute this code
			
		}
		else //if there is a touch
		{
			//loop through all the touches on screen
			for (int t = 0; t < Input.touchCount; t++)
			{
				//execute this code for the next touch (i)
				
				if(Input.GetMouseButton(0)  this.guiTexture.HitTest(Input.GetTouch(t).position))
				{
					//if current touch hits our guitexture, run this code
					if(Input.GetTouch(t).phase == TouchPhase.Began)
					{
                                        }
if(Input.GetTouch(t).phase == TouchPhase.Began)

isn’t this checking to see if the touch is “new”… so it’ll only happen when the player first touches the screen and not the frame after that

im all ears like i said touch input is new to me

bump

bump

This is like the last thing stopping my games progress any insight would be great guys thanks i just want to continue movement while holding the GUI button and it seems it on moves once each tap?

LeftyRighty already answered by pointing the TouchPhase.Began is only true when the touch has just began but not while keep touching your GUI Texture.
You either have to look for a proper TouchPhase parameter or trying to solve it on another way like setting a boolean to true when the touch began and having a separate code block for moving your player when the touch-boolean is true.

mmm looks like im going to have to find another implementation then because i dont see anything in the touchphase hierarchy that would help

When using touch states, you want to make it fire so long as its a touch in progress…

I personally use…

foreach (Touch touch in Input.touches) 
{
            if (touch.phase != TouchPhase.Began  touch.phase != TouchPhase.Ended)
                {
MovePlayer();
}
}

Something like this will only fire if the touchstate is NOT began or ended, and will only fire IF you have a touch on the screen.

ok so to make sure im understanding you correctly, this piece of code will run as long as there is a touch so this should work to help my character walk/run correct?

That code will constantly fire, so long as there is a touch on the screen that is in neither the Began, or ended phase.

I use it a lot in my own projects to track touches over time.

cool thanks ill give it a try thanks for your time

One of the TouchPhase.Ended needs to become a TouchPhases.Began

Thanks, I fixed my response.
Hey, I never said I don’t make typos :P. (Or accidentally use the same variable twice!)