0 Replies - 1714 Views - Last Post: 11 May 2014 - 11:59 AM

#1 bboyzeez  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 143
  • Joined: 16-December 12

Unity joystick and shoot touch problems

Posted 11 May 2014 - 11:59 AM

hi all

so i am having a problem i have a little guitexture which when you touch on it i want it to move a crosshair on screen now i want it so only while the finger which touched the guitexture to adjust the crosshair.

my problem is it works but if i touch the screen a second time it messes with the first touch and the crosshair goes all over the place

is there a way to restrict the movement of the crosshair to always the first touch on screen and any others dont affect it?

if (joyStick.HitTest(Input.GetTouch(0).position))
		{
			if(Input.GetTouch(0).phase==TouchPhase.Began)
			{
				startPos = Input.GetTouch(0).position;
			}

			if(Input.GetTouch(0).phase==TouchPhase.Stationary)
			{
				endPos = Input.GetTouch(0).position;
				if(startPos.x < endPos.x)
				{
					crosshair.transform.Translate(moveX * speed,0,0);
				}
				if(startPos.x > endPos.x)
				{
					//move left
					crosshair.transform.Translate(-moveX * speed,0,0);
				}
				if(startPos.y < endPos.y)
				{
					crosshair.transform.Translate(0,moveX * speed,0);
				}
				if(startPos.y > endPos.y)
				{
					//move left
					crosshair.transform.Translate(0,-moveX * speed,0);
				}
			}

			if(Input.GetTouch(0).phase==TouchPhase.Moved)
			{
				//check where user moves joystick
				endPos = Input.GetTouch(0).position;
				if(startPos.x < endPos.x)
				{
					crosshair.transform.Translate(moveX * speed,0,0);
				}
				if(startPos.x > endPos.x)
				{
					//move left
					crosshair.transform.Translate(-moveX * speed,0,0);
				}
				if(startPos.y < endPos.y)
				{
					crosshair.transform.Translate(0,moveX * speed,0);
				}
				if(startPos.y > endPos.y)
				{
					//move left
					crosshair.transform.Translate(0,-moveX * speed,0);
				}

			}
			if(Input.GetTouch(0).phase==TouchPhase.Ended)
			{
				
			}
	}
	}


i know i have duplicated code here and there is probs a better way but ill clean that up after i have fixed this problem

Is This A Good Question/Topic? 0
  • +

Page 1 of 1