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 Davethesloth · Jul 10, 2014 at 03:06 PM · variablefunctionvaluefmodangry bots

Variable won't update within a certain function

I'm having a bit of fun with the Angry Bots project and the FMOD intergration provided by Sound Librarian http://www.soundlibrarian.com/uploads/3 ... torial.pdf

I've been trying to automate the footsteps so that they sound different depending on whether the player is outside or inside. Here's my code so far:

 #pragma strict
 
 class FootstepHandler extends MonoBehaviour 
 {
 
 enum FootType 
 {
    Player,
    Mech,
    Spider
 }
 
 public var audioSource : AudioSource;
 public var footType : FootType;
 
 private var evt : FMOD.Studio.EventInstance;
 private var param : FMOD.Studio.ParameterInstance;
 private var attributes : FMOD.Studio._3D_ATTRIBUTES;
 
 public var isOutside = true;
 
 public var physicMaterial : PhysicMaterial;
 
 private var eventPath : String;
 
 static var sInstance : FootstepHandler = null;
    static function instance() : FootstepHandler
    {
       return sInstance;
    }
    
    function Awake()
    {
       sInstance = this;      
    }
                                              
                                                       
 function OnCollisionEnter (collisionInfo : Collision) 
 {
    physicMaterial = collisionInfo.collider.sharedMaterial;      
 }
 
 
 function OnFootstep () 
 {    
    switch (footType)    
    {
    case FootType.Player:
       eventPath = MaterialImpactManager.GetPlayerFootstepSound(physicMaterial);
       break;
    case FootType.Mech:
       eventPath = MaterialImpactManager.GetMechFootstepSound(physicMaterial);
       break;
    case FootType.Spider:
       eventPath = MaterialImpactManager.GetSpiderFootstepSound(physicMaterial);
       break;
    }   
    
    if (!String.IsNullOrEmpty(eventPath))
    evt = FMOD_StudioSystem.instance.GetEvent(eventPath);
    attributes = FMOD.Studio.UnityUtil.to3DAttributes(transform.position);
    evt.set3DAttributes(attributes);
    evt.getParameter("Wet", param);   
       
    param.setValue(isOutside ? 1.0f : 0.0f);
             
    evt.start();
    evt.release();      
                                              
 }
                                                                                        
 public function setOutside(outside : boolean)
 {
    isOutside = outside;
    print("Footstep Transition: " + (outside ? "Outside" : "Inside"));
 }      
          
 }
       

Angry Bots is using 'MoodBoxes' to trigger changes when the player walks through them. In the script above, the function setOutside() is using data from those MoodBoxes (in another script) to switch between Inside and Outside. The value is assigned to a boolean variable called isOutside, and that value is then used to modify the FMOD parameter within the OnFootstep() function.

Here's my problem though: the isOutside variable won't update within the OnFootstep() function. It works fine within setOutside(), and Update() for example but not in OnFootstep().

The 'outside' boolean switches between true and false depending on the player's position. This line

 print("Footstep Transition: " + (outside ? "Outside" : "Inside"));

allows me to check that it is updated normally and works fine. I assign 'isOutside' to 'outside' which means isOutside should now update according to the player's position.

Now if i print to console within the Update() function using this line :

 print("isOutside Check: " + (isOutside ? "True" : "False"));

, I can confirm that isOutside switches normally between true and false and works fine. But the same print line within the OnFootstep() function shows that 'isOutside' is not being updated at all and doesn't switch between true and false. And i've no idea why....

Anyone has any idea how I could pass that value? Hopefully it's something quite easy or obvious i'm missing, but I've been pulling my hair out on this one and here's hoping someone can help.

Thanks in advance and let me know if you need any more detail.

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

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

changing variables values !! 1 Answer

iTween - calling functions on oncomplete doesn't work if the function is declared as a variable 1 Answer

Getting error: Cannot modify a value type return value of `UnityEngine.Rigidbody.velocity'. Consider storing the value in a temporary variable 1 Answer

Trying to pass a float value from a prefab to another script that compares values from multiple prefabs 1 Answer

cant assign variables value 2 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