Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by bruu · Feb 27, 2014 at 05:05 PM · movementaudioaccelerometer

Audio playing if user (The actual person) is moving

I'm trying to find out how to keep an audio playing if the user is moving (with the device in their pocket). And how to stop the audio when the user stops moving with his device.

How would i go about achieving this? This is my code so far, it doesn't work at all. The audio just plays no matter what. Can't even stop the audio with my pause/stop button.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class PlayButton : MonoBehaviour
 {
     public GameObject chapter1;
     public Vector3 userMovement;
 
     void FixedUpdate()
     {
 
 
         chapter1 = GameObject.Find("Chapter 1");
 
         userMovement = Input.acceleration;
 
         
         if (userMovement.x > 0 || userMovement.y > 0 || userMovement.z > 0 && !chapter1.audio.isPlaying)
         {
             chapter1.audio.Play();
 
         }
         
 
     }
 
 
 
     public void OnClick( dfControl control, dfMouseEventArgs mouseEvent )
     {
         // Add event handler code here
 
         
         chapter1.audio.Play();
 
 
 
     }
 
 
 
    
 
 }
 
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by FinKone · Feb 27, 2014 at 05:23 PM

Could use two vector 3s. Have one as currentPosition, and lastPosition, then play the sound if current doesnt equal last, and at the end update last to the current. Have current tracking the objects current position and have last update to current. Not the most accurate way but simple.

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 bruu · Feb 27, 2014 at 05:28 PM 0
Share

Sorry, but this does not answer my question. I want the audio to play if the device is actually moving (the actual real life person moving)

avatar image
0

Answer by roojerry · Feb 27, 2014 at 05:55 PM

Look into Gyroscope.userAcceleration.

I would assume you could check for some sustained acceleration over time (with some tolerance), to determine if the user is moving with their device. It may take some tweaking to get this right.

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 bruu · Feb 27, 2014 at 06:00 PM 0
Share

Thank you for your reply.

I have tried to use Gyroscope.userAcceleration but to no avail. I'm using android, if that matters.

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

22 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

Related Questions

move gameObject on z dependently on iOS device movement on x axis... 1 Answer

Virtual Reality: Move player when mobile moves 0 Answers

Mobile Movement Choppy in 2d endless runner 0 Answers

Android Shake 0 Answers

How can I calibrate phone accelerometer? 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