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 ();
             }
         }
 }
} }
Answer by shadowpuppet · Aug 15, 2016 at 06:43 PM
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);
Your answer
 
 
             Follow this Question
Related Questions
Player follow touch when holding down your finger on the screen (C#) 1 Answer
How to pick up an object when touching a button(Mobile) 0 Answers
Non-responsive touch controls after showing ads. 0 Answers
Massive lag spike on first Input.GetTouch with nothing on scene but one script (Android) 2 Answers
Having an issue with touch input lag on certain Android devices, any help? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                