Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
avatar image
1
Question by pandagamingroyt · Apr 14, 2021 at 10:53 PM · inputaxissystemsensorproximity

How to get sensor values with the Input System?

I am trying to get the distance value from the proximity sensor by using unity's Input System but nothing that I tried seems to work. I tried looking into the documentation, there it says something about "AxisControl" but I have no clue how to code it to work. https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/api/UnityEngine.InputSystem.ProximitySensor.html

This my code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.InputSystem;
 using TMPro;
 using System;
 public class Sensors : MonoBehaviour
 {
     public TMP_Text textprox;
     public ProximitySensor proximity;
 
     void Start()
     {
         proximity = ProximitySensor.current;
     }
 
     void Update()
     {
         if(proximity != null)
         {
             InputSystem.EnableDevice(proximity);
             var _ProximitySensor = ProximitySensor.current;
             var _dist = _ProximitySensor.distance;
             textprox.text = "Proxy: " + _dist;
         }
         else
         {
             textprox.text = "null";
         }
     }
 }


Comment
Add comment · Show 1
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
avatar image HellsHand · Apr 14, 2021 at 11:30 PM 0
Share

I haven't used sensors before but something about your code stands out. In your Start() you're setting proximity as the current input, then in your Update() you're enabling proximity, but setting _ProximitySensor as the current input and getting the distance from that when it hasn't been enabled. I may just be ignorant of the way this works but that seems rather wrong to me. Wouldn't you wanna get the distance from the enabled device?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Roman_Keivan · Sep 05, 2021 at 10:42 PM

@pandagamingroyt > Try this


 public float ProximityDistanceSensor(bool m_isActiveProxSens, float m_frequency = 16f)
             {
                 proximitySensor.samplingFrequency = m_frequency; // Set sampling frequency of proximitySensor to sample 16 times per second.
                 
                 if (m_isActiveProxSens)
                 {
                     InputSystem.EnableDevice(proximitySensor);
                     Debug.Log("Proximity sensor is: " + proximitySensor.enabled);
                 }
                 else
                 {
                     InputSystem.DisableDevice(proximitySensor);
                     Debug.Log("Proximity sensor is: " + proximitySensor.enabled);
                 }
     
                 return actionControlls.UI.DistanceActionSensor.ReadValue<float>();
             }
 
 
 
 


Comment
Add comment · Show 1 · Share
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
avatar image legendfromtn1 · Nov 02, 2021 at 02:57 PM 0
Share

your code is not working. actionControlls is not declared and does not exist can you fix this please I really need to work on this sensor

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

153 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 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 avatar image avatar image avatar image

Related Questions

Steering Wheel / joystick GetAxis trouble 0 Answers

Reset Input.GetAxis Back to 0 0 Answers

How to take input from the fingerprint sensor,which is now becoming a part of more or less every android device???? 1 Answer

Write custom input manager 0 Answers

Controller Joystick Hold Delay Logic? 1 Answer


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