Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Eastrauss · Oct 21, 2016 at 07:27 AM · input.touch

input issues

I'am new to coding, and i'm having issues with a script i'm working with. The script is a detection script that lets me open doors and close them within my current project. The issue i'm having is that I need to use a GUI button for the door to open but the script is designed to work with a keyboard input. I've tried using Input.GetButtonDown and it doesn't seem to work. Here's the script for example

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 public class Detection : MonoBehaviour
 {
     // INSPECTOR SETTINGS
     [Header("Detection Settings")]
     [Tooltip("Within this radius the player is able to open/close the door")]
     public float Reach = 4F;
     [Tooltip("The tag that triggers the object to be openable")]
     public string TriggerTag = "Door";
 
     // PRIVATE SETTINGS
     [HideInInspector] public bool InReach;
 
     //DEBUGGING (DEBUG PANEL)
     [Header("Debug Settings")]
     public Color DebugRayColor = Color.green;
     public bool InGameDebugger = false;
 
     string CategoryDetection = "Detection";
     string TitleReach = "Reach";
     string TitleInReach = "InReach";
 
     string CategoryDoor = "Door";
     string TitleHitTag = "HitTag";
     string TitleHingeSide = "HingeSide";
     string TitleCurrentAngle = "CurrentAngle";
     string TitleSpeed = "Speed";
     string TitleTimesMoveable = "TimesMoveable";
     string TitleRunning = "Running";
 
     //START FUNCTION
     void Start()
     {
 
     }
 
     //UPDATE FUNCTION
     void Update()
     {
         // Set origin of ray to 'center of screen' and direction of ray to 'cameraview'.
         Ray ray = Camera.main.ViewportPointToRay (new Vector3 (0.5F, 0.5F, 0F));
 
         RaycastHit hit; // Variable reading information about the collider hit.
 
         // Cast a ray from the center of screen towards where the player is looking.
         if (Physics.Raycast (ray, out hit, Reach))
         {
             //DEBUGGING (DEBUG PANEL)
             DebugPanel.Log(TitleHitTag, CategoryDoor, hit.collider.tag);
 
             if(hit.collider.tag == TriggerTag)
             {
                 InReach = true;
 
                 if (Input.GetButtonDown("Open/Close"))
                     
                 {
                     // Give the object that was hit the name 'Door'.
                     GameObject Door = hit.transform.gameObject;
 
                     // Get access to the 'DoorOpening' script attached to the door that was hit.
                     Door dooropening = Door.GetComponent<Door>();
 
                     // Check whether the door is opening/closing or not.
                     if (dooropening.Running == false)
                     {
                         // Open/close the door by running the 'Open' function in the 'DoorOpening' script.
                         StartCoroutine (hit.collider.GetComponent<Door>().Open());
                     }
                 }
             }
 
             else InReach = false;
 
         }
 
         else
         {
             InReach = false;
 
             //DEBUGGING (DEBUG PANEL)
             DebugPanel.Break(TitleHitTag);
         }
 
         //DEBUGGING (DEBUG PANEL)
         DebugPanel.Log(TitleInReach, CategoryDetection, InReach);
         DebugPanel.Log(TitleReach, CategoryDetection, Reach);
 
         if (InReach == true)
         {
             DebugPanel.Log (TitleHingeSide, CategoryDoor, hit.collider.GetComponent<Door>().HingeSide);
             DebugPanel.Log (TitleSpeed, CategoryDoor, hit.collider.GetComponent<Door> ().Speed);
             DebugPanel.Log (TitleTimesMoveable, CategoryDoor, hit.collider.GetComponent<Door> ().TimesMoveable);
             DebugPanel.Log (TitleCurrentAngle, CategoryDoor, Mathf.Round(hit.transform.eulerAngles.y) + "°");
             DebugPanel.Log (TitleRunning, CategoryDoor, hit.collider.GetComponent<Door> ().Running);
         }
 
         else
         {
             DebugPanel.Break (TitleHingeSide);
             DebugPanel.Break (TitleSpeed);
             DebugPanel.Break (TitleTimesMoveable);
             DebugPanel.Break (TitleCurrentAngle);
             DebugPanel.Break (TitleRunning);
         }
 
         // Draw the ray as a colored line for debugging purposes.
         Debug.DrawRay (ray.origin, ray.direction*Reach, DebugRayColor);
     }
 }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

75 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Input.touch webgl doesnt work 0 Answers

Input Touch Not Working Quite Right... 1 Answer

Are multiple screens that are all touch screens possible for unity? 0 Answers

can't detect touch on screen 0 Answers

TouchScreen Controls? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges