البرمجة

تشغيل الصوت مع الرسوم المتحركة في Unity

To play audio while an animation is running in Unity 3D, you can use the Animation Events feature. Here’s a step-by-step guide:

  1. Add an Audio Source: First, make sure you have an Audio Source component attached to your GameObject. This component will play the audio clip.

  2. Attach the Audio Clip: Assign the audio clip you want to play to the Audio Source component.

  3. Create Animation Events: In the Animation window, select the animation clip you want to add audio to. Right-click on the timeline where you want the audio to start playing, then select “Add Animation Event.”

  4. Set Up the Animation Event: In the Animation Event window, set the function to call to play the audio. You can create a new method in a script for this purpose.

  5. Write a Script: Create a new C# script and attach it to the GameObject with the Animator component. In this script, define a method that plays the audio clip.

Here’s an example script:

csharp
using UnityEngine; public class AudioController : MonoBehaviour { public AudioSource audioSource; public void PlayAudio() { if (audioSource != null) { audioSource.Play(); } } }
  1. Attach the Script to the GameObject: Drag the script onto the GameObject with the Animator component.

  2. Call the Method from the Animation Event: In the Animation Event window, select the method you created in the script to play the audio.

  3. Test the Animation: Play the animation in Unity. The audio should now play at the specified time during the animation.

By following these steps, you can play audio while an animation is running in Unity 3D.

المزيد من المعلومات

بالطبع! في Unity 3D، يمكنك تشغيل الصوت أثناء تشغيل الرسوم المتحركة باستخدام مكون الصوت AudioSource وحدث الرسوم المتحركة Animation Events. إليك كيفية القيام بذلك بالتفصيل:

  1. إضافة مكون AudioSource: قم بإلصاق مكون AudioSource إلى الكائن الذي تريد تشغيل الصوت منه. يمكنك القيام بذلك عن طريق النقر بزر الماوس الأيمن على الكائن في الهرم واختيار “Add Component” ثم “Audio” وأخيرًا “Audio Source”.

  2. تعيين ملف الصوت: قم بتعيين ملف الصوت الذي تريد تشغيله إلى مكون AudioSource.

  3. إنشاء حدث الرسوم المتحركة: في نافذة الرسوم المتحركة Animation، حدد مقطع الرسوم المتحركة الذي تريد إضافة الصوت إليه. انقر بزر الماوس الأيمن على الجدول الزمني حيث تريد بدء تشغيل الصوت، ثم اختر “Add Animation Event”.

  4. ضبط حدث الرسوم المتحركة: في نافذة حدث الرسوم المتحركة، ضبط الدالة التي ستستدعى لتشغيل الصوت. يمكنك إنشاء طريقة جديدة في سكريبت لهذا الغرض.

  5. كتابة سكريبت: أنشئ سكريبت C# جديد وألصقه على الكائن الذي يحتوي على مكون Animator. في هذا السكريبت، قم بتعريف طريقة تشغيل ملف الصوت.

csharp
using UnityEngine; public class AudioController : MonoBehaviour { public AudioSource audioSource; public void PlayAudio() { if (audioSource != null) { audioSource.Play(); } } }
  1. إلصاق السكريبت بالكائن: اسحب السكريبت إلى الكائن الذي يحتوي على مكون Animator.

  2. استدعاء الطريقة من حدث الرسوم المتحركة: في نافذة حدث الرسوم المتحركة، حدد الطريقة التي قمت بإنشائها في السكريبت لتشغيل الصوت.

  3. اختبار الرسوم المتحركة: شغّل الرسوم المتحركة في Unity. يجب أن يتم تشغيل الصوت الآن في الوقت المحدد خلال الرسوم المتحركة.

من خلال اتباع هذه الخطوات، يمكنك تشغيل الصوت أثناء تشغيل الرسوم المتحركة في Unity 3D.

مقالات ذات صلة

زر الذهاب إلى الأعلى
إغلاق

أنت تستخدم إضافة Adblock

يرجى تعطيل مانع الإعلانات حيث أن موقعنا غير مزعج ولا بأس من عرض الأعلانات لك فهي تعتبر كمصدر دخل لنا و دعم مقدم منك لنا لنستمر في تقديم المحتوى المناسب و المفيد لك فلا تبخل بدعمنا عزيزي الزائر