<span id="Label3"></p><p><p><br></p></p><p><p><span style="font-size:14px">To invoke the vibrations of the Android system in unity, you need a vibrator class that sets permissions through the Androidmanifest.xml file.</span></p></p><p><p><span style="font-size:14px">As follows:</span></p></p><p><p><span style="font-size:14px"></span></p></p><pre name="code" class="html"><pre name="code" class="html"><uses-permission android:name= "android.permission.VIBRATE"/></pre></pre><br>Here first to post the English document and the approximate translation:<p><p></p></p><p><p><br></p></p><p><p><span style="font-size:14px">Class that operates the vibrator on the Device.<br>If your process exits, any vibration you started with would stop.<br><br>The vibrator class is used to manipulate vibrations on the device, and if your thread exits, the starting vibration will Stop.</span></p></p><p><p> <span style="font-size:14px">pass in a array of ints that is the durations for which to turn on or off the vibrator I N MILLISECONDS. The first value indicates the number of milliseconds to wait before turning the vibrator On. The next value indicates the number of milliseconds for which to keep the vibrator on before turning it off. Subsequent values alternate between durations in milliseconds to turn the vibrator off or to turn the vibrator On. </span> </p></p><p><p><span style="font-size:14px">An integer array is passed as the duration of the shutdown and turn-on vibration, in MILLISECONDS. The first value indicates the number of milliseconds to wait for the vibration to open, and the next value indicates the number of milliseconds to hold the vibration, alternating the number of milliseconds that the vibration is closed and turned On.<br><br>To cause the pattern to repeat, pass the "index into the" the pattern array at which to start the repeat, or-1 to disable Repea Ting.<br>In order to repeat the set rhythm vibration, passing the index parameter indicates the number of repetitions, with 1 means no Repetition.<br><br>Parameters<br>Pattern an array of longs of times for which to turn the vibrator on or off.<br>Repeat the index into the pattern at which to repeat, or-1 if you don ' t want to repeat.</span></p></p><p><p><br></p></p><p><p><span style="font-size:14px">On the Code:</span></p></p><p><p><span style="font-size:14px"></span></p></p><pre name="code" class="java"><pre name="code" class="java">public void Startshock (long [] mpattern,int Index) {vibrator = (vibrator) Getsystemservice (context.vibrator_service); Long [] pattern = {100,400,100,400}; Pattern = Mpattern;vibrator.vibrate (pattern,index);}</pre></pre><br>Two parameters are set here to allow for flexible definition of vibrations in unity;<p><p></p></p><p><p><span style="font-size:14px">There are also:</span></p></p><p><p><span style="font-size:14px"></span></p></p><pre name="code" class="java"><pre name="code" class="java">public void OnStop () { super.onstop (); Vibrator.cancel (); </pre></pre><br><p><p></p></p><p><p><span style="font-size:14px">Then clean up your Android project and then play your own jar package ( <span style="font-size:14px">or</span> use the command line: JAR-CVF Myclass.jar * (OMITTED)) to place the packaged jar package in the Unity Project ("plugins/ Android/libs ");</span></p></p><p><p><span style="font-size:14px">We'd better go back to unity and create a new C # script,</span></p></p><p><p><span style="font-size:14px">Post the Code:</span></p></p><p><p><span style="font-size:14px"></span></p></p><pre name="code" class="csharp"><pre name="code" class="csharp">public static void Playshock () {//#if unity_android &&! Unity_editorif (mshockenable) {long[] shock = new long[] {+, +};using (androidjavaclass JC = new Androidjavaclass ("c Om.unity3d.player.UnityPlayer ")) {androidjavaobject jo = jc. Getstatic<androidjavaobject> ("currentactivity"); Jo. Call ("startshock", shock,-1);} } #endif}</pre></pre><p><p></p></p><p><p><span style="font-size:14px">This method is used to invoke native vibrations of android.</span></p></p><p><p><span style="font-size:14px">This tutorial is relatively simple, there are good suggestions, Welcome to light spray!</span><br></p></p><p><p>Unity calls Android native vibration (simple)</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service