- Home /
How to implement multitouch?
I am trying to implement multitouch. I made a game to mobile and when I tried it out, multitouch didn't work. The game is a 4 player local multiplayer where each player moves their character with a button and when I gave it a try on my phone. Multitouch did not work. Is there anyone that can rewrite the code and explain me, how to make it multitouch compatible? Thank you
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class TankScript : MonoBehaviour { private float moveSpeed = 200f; public int ChangeDirection; public float movementSpeed = 5f; Rigidbody2D rb; private Vector3 direction; public Camera MainCamera;
void Awake()
{
ChangeDirection = 0;
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
Vector3 tankObject = transform.position;
transform.RotateAround(tankObject, Vector3.forward, moveSpeed * Time.deltaTime);
}
public void MoveForward()
{
if (Input.GetMouseButtonDown(0))
{
moveSpeed = 0f;
rb.velocity = transform.up * 1 * movementSpeed;
if (ChangeDirection == 0)
{
ChangeDirection = 1;
}
else
ChangeDirection = 0;
}
}
public void SpinSomeMore()
{
if (Input.GetMouseButtonUp(0) && ChangeDirection == 1)
{
moveSpeed = 200f;
rb.velocity = transform.up * 0 * movementSpeed;
}
if (Input.GetMouseButtonUp(0) && ChangeDirection == 0)
{
moveSpeed = -200f;
rb.velocity = transform.up * 0 * movementSpeed;
}
}
}
Your answer
Follow this Question
Related Questions
Multitouch on Windows 7? 7 Answers
Unity Remote 3 and accessing multiple Input.touches? 3 Answers
Car MultiTouch Controls 0 Answers
Multi-touch problem in a 2 player pong game 2 Answers
Does unity now support multitouch directly in windows? 1 Answer