Please Help Im confuse im beginner in using unity.

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 ();
			}
		}
}

}
}

not sure about all this coding, but I have a ray script that limits how far the ray casts, doesn’t look like your s does. iN the code from my camera the “6” is how far the raycasts. a "2’ is about arms length I think. maybe that’s the problem, you’re casting to far

Ray ray = camera.ViewportPointToRay(new Vector3(0.5F, 0.5F, 6));
		RaycastHit hit;
		if (Physics.Raycast(ray, out hit,6))
		{
			Debug.DrawLine(ray.origin, hit.point);