- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
lawrrennce · Nov 16, 2019 at 02:43 PM ·
c#mobilemultitouchtouchphase
Multi touch on mobile game
I'm making a mobile game and is currently facing an issue with multi touch. The game character was controlled by using a joystick pack from Unity asset store. There is a power-up inside the game for players to collect by tapping on it. However, while I'm controlling the game character (Holding the joystick), I'm unable to tap the object at the same time but it works when I'm not using the joystick. Thanks in advance.
Here's the script for the game character:
public float moveSpeed = 2f;
public float forwardMovementSpeed = 3.0f;
public Rigidbody2D rb;
public Joystick joystick;
Vector2 movement;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
movement.y = joystick.Vertical;
}
void FixedUpdate()
{
rb.MovePosition(rb.position + new Vector2(forwardMovementSpeed * Time.fixedDeltaTime, movement.y * moveSpeed * Time.fixedDeltaTime));
}
Here's the script for the power-up:
public GameObject LikeButton;
Collider2D col;
void Start()
{
col = GetComponent<Collider2D>();
}
public void Update()
{
if (Input.touchCount < 0)
{
Touch touch = Input.GetTouch(0);
Vector2 touchPosition = Camera.main.ScreenToWorldPoint(touch.position);
if (touch.phase == TouchPhase.Began)
{
Collider2D touchedCollider = Physics2D.OverlapPoint(touchPosition);
if (col == touchedCollider)
{
Destroy(gameObject);
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Two player touch screen 1 Answer
Multitouch physics drag with TargetJoint2D 0 Answers
Multiple Cars not working 1 Answer
Two or more touchs at same time? 0 Answers
Distribute terrain in zones 3 Answers