i want to add touch controlls to my game. how can i do so? *free candy for whoever helps me out*
so i want to add touch controlls to my game, and i have no idea how to do so. could someone help me out with this? the script im using for my controls is: using UnityEngine; using UnityEngine.UI; using System.Collections; using UnityEngine.SceneManagement;
public class PlayerController : MonoBehaviour
{
public float speed;
public Text countText;
public Text winText;
private Rigidbody rb;
private int count;
void Start()
{
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText();
winText.text = "";
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Pick Up"))
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText();
}
}
void SetCountText()
{
countText.text = "Count: " + count.ToString();
if (count >= 12)
{
winText.text = "You Win!";
}
}
}
will i have to create a new version of the script that can work on touch devices like android and ios or can i just edit this script? im really new to scripting and unity so yeah lol
Answer by Xpartano · Feb 28, 2018 at 04:13 PM
Here you have a good start.
https://docs.unity3d.com/Manual/MobileInput.html
And a basic video tutorial of Mobile controls:
https://unity3d.com/es/learn/tutorials/projects/2d-roguelike-tutorial/adding-mobile-controls
Your answer
Follow this Question
Related Questions
How do is make Unity 8-way swipe touch control code 0 Answers
ScreenToWorldPoint on One Axis? 0 Answers
iOS touch delay? 0 Answers
Rotate object by touch using Angles? 0 Answers
New input system and touch on webgl 1 Answer