• 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 JackQuinton · May 04, 2017 at 01:29 PM · audiofmod

How to link a fmod parameter to int in script?

I've been trying to code this from the unity fmod survival shooter tutorial for days and can't figure it out. here is the code i'm using with some attempts at linking it.

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 using UnityEngine.SceneManagement;
 
 namespace CompleteProject
 {
     public class PlayerHealth : MonoBehaviour
     {
         public int startingHealth = 100;                            // The amount of health the player starts the game with.
         public int currentHealth;                                   // The current health the player has.
         public Slider healthSlider;                                 // Reference to the UI's health bar.
         public Image damageImage;                                   // Reference to an image to flash on the screen on being hurt.
         public float flashSpeed = 5f;                               // The speed the damageImage will fade at.
         public Color flashColour = new Color(1f, 0f, 0f, 0.1f);     // The colour the damageImage is set to, to flash.
 
 
 
         private FMODUnity.StudioEventEmitter Heartbeat;
 
         [FMODUnity.EventRef]
         public string HeartSound;
 
         FMOD.Studio.EventInstance playerState;
 
 
         Animator anim;                                              // Reference to the Animator component.
         PlayerMovement playerMovement;                              // Reference to the player's movement.
         PlayerShooting playerShooting;                              // Reference to the PlayerShooting script.
         bool isDead;                                                // Whether the player is dead.
         bool damaged;                                               // True when the player gets damaged.
 
 
         void Awake ()
         {
             // Setting up the references.
             anim = GetComponent <Animator> ();
             playerMovement = GetComponent <PlayerMovement> ();
             playerShooting = GetComponentInChildren <PlayerShooting> ();
 
             // Set the initial health of the player.
             currentHealth = startingHealth;
 
             Heartbeat = GetComponent<FMODUnity.StudioEventEmitter>();
         }
 
 
         void Update ()
         {
             // If the player has just been damaged...
             if(damaged)
             {
                 // ... set the colour of the damageImage to the flash colour.
                 damageImage.color = flashColour;
             }
             // Otherwise...
             else
             {
                 // ... transition the colour back to clear.
                 damageImage.color = Color.Lerp (damageImage.color, Color.clear, flashSpeed * Time.deltaTime);
             }
 
             // Reset the damaged flag.
             damaged = false;
 
 
 
             // "setParameterValue" is showing up as red
             HeartSound.setParameterValue("health", (float)currentHealth);
          
 
         }
 
        
 
 
         public void TakeDamage (int amount)
         {
             // Set the damaged flag so the screen will flash.
             damaged = true;
 
             // Reduce the current health by the damage amount.
             currentHealth -= amount;
 
             // Set the health bar's value to the current health.
             healthSlider.value = currentHealth;
 
             // Play the hurt sound effect.
 
             // If the player has lost all it's health and the death flag hasn't been set yet...
             if(currentHealth <= 0 && !isDead)
             {
                 // ... it should die.
                 Death ();
             }
 
             //if (Health <= 40)
            //{
          
 
         }
 
 
         void Death ()
         {
             // Set the death flag so this function won't be called again.
             isDead = true;
 
             // Turn off any remaining shooting effects.
             playerShooting.DisableEffects ();
 
             // Tell the animator that the player is dead.
             anim.SetTrigger ("Die");
 
             // Set the audiosource to play the death clip and play it (this will stop the hurt sound from playing).
 
             // Turn off the movement and shooting scripts.
             playerMovement.enabled = false;
             playerShooting.enabled = false;
         }
 
 
         public void RestartLevel ()
         {
             // Reload the level that is currently loaded.
             SceneManager.LoadScene (0);
         }
     }
 }

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 juanklot · May 09, 2017 at 05:19 AM

Hi Jack,

I answered your question here:

https://www.youtube.com/watch?v=d9pKaE_IyP4

Comment
Add comment · 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
0

Answer by juanklot · May 09, 2017 at 05:42 AM

Hi Jack,

PlayerHealth.cs

[FMODUnity.EventRef] public string _eventSound; FMOD.Studio.EventInstance _eventInstance; FMOD.Studio.ParameterInstance _myParameter; public string _parameter;

void Awake() { _eventInstance = FMODUnity.RuntimeManager.CreateInstance (_eventSound); _eventInstance.getParameter(_parameter, out _myParameter); _eventInstance.start (); } void Update () { _myParameter.setValue (currentHealth); }

then select your event and write the name of your parameter in the inspector.

Comment
Add comment · 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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Audio source not playing 7 Answers

FMOD Error from loaded asset bundle 0 Answers

How can I use multichannel audio in a game? 0 Answers

Disable Unity audio/FMOD on iOS 0 Answers

Turning off FMOD 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