Please help me I’m developing an FPS android game for my thesis proj. all i want to know is how can I open the door when i touch the door with corresponding distance im confused and i dont know how to fix because when i test the game on my cellphone whenever i look on the door it opens without touching anything maybe because of the raycast but how can i open the door through a touch with a corresponding distance. Please Help.
My code :
using UnityEngine;
using System.Collections;
public class Interact : MonoBehaviour {
public float InteractDistance = 3f;
void Start () {
}
void Update ()
{
foreach(Touch touch in Input.touches) {
Ray ray = new Ray (transform.position, transform.forward);
RaycastHit hit;
if (Physics.Raycast (ray, out hit, InteractDistance))
{
if (hit.collider.CompareTag ("Door"))
{
hit.collider.transform.parent.GetComponent<Door> ().ChangeDoorState ();
}
}
}
}
}