Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by InfluxOG · May 03, 2016 at 06:54 PM · collision detectionevent triggering

Trying to get my OnTriggerEvent to run more than once

Basically I am working on a game where when the player enters the area of the enemy (i'm using a sphere collider) the OnTriggerEvent method is run so that the enemy makes a noise, which works fine, the problem is when I leave the area and go back inside, it wont do it again, the debug log still detects me as being inside the area even when I have left, how do I make it so it'll work on re-entry too? Here's the script just in case.

alt text

9d6d2ed4a860dab5ae43be1127918a70.png (17.4 kB)
Comment
Add comment · Show 6
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 brunocoimbra · May 03, 2016 at 07:56 PM 0
Share

Create a Debug.Log inside the if statement and post your Audio$$anonymous$$anager code.

Also, don't print your code, copy paste it here and don't forget to use the 101010 button to format it correctly.

avatar image InfluxOG brunocoimbra · May 03, 2016 at 11:18 PM 0
Share

The only code for the audio manager itself is the cs script that comes with the program, which is never altered. However I can show you my hierarchy of my audio components in cse that's useful. Just in case also, here's my Audio manager cs file:

 using UnityEngine;
 using System.Collections;
 
 public static class Audio$$anonymous$$anager
 {
 
     private static void playAudio(string eventName)
     {
         //AUDIO: without position
         Fabric.Event$$anonymous$$anager.Instance.PostEvent(eventName);
     }
 
     private static void playAudioWithPosition(string eventName, GameObject ob)
     {    
         //AUDIO: with position
         Fabric.Event$$anonymous$$anager.Instance.PostEvent(eventName, ob);
     }
 
     public static bool FabricLoaded {get { return Fabric.Event$$anonymous$$anager.Instance; }}
 
 
     public static void PlaySound(string n)
     {
         LoadFabric();
         if (FabricLoaded)
             playAudio(n);
     }
 
     public static void PlaySound(string n, GameObject ob)
     {
         LoadFabric();
         if (FabricLoaded)
             playAudioWithPosition(n, ob);
     }
 
     public static void StopSound(string n)
     {
         Fabric.Event$$anonymous$$anager.Instance.PostEvent(n, Fabric.EventAction.StopAll);
     }
 
     public static void FadeOut$$anonymous$$usic(string n) {
         // fade out the music!
         Fabric.Component component = Fabric.Fabric$$anonymous$$anager.Instance.GetComponentByName(n);
         if (component != null) {
             component.FadeOut(0.1f, 0.5f);
         }
     }
 
     public static void SetDialogLine(string dialogEvent, string componentName)
     {
         Fabric.Event$$anonymous$$anager.Instance.PostEvent(componentName, Fabric.EventAction.SetAudioClipReference, dialogEvent);
     }
 
     public static void LoadFabric()
     {
         if (FabricLoaded) { // || Application.isLoadingLevel) {
             return;
         }
         Application.LoadLevelAdditive("_Audio_");
     }
 
     public static bool IsSoundStillPlaying ( string n)
     {
         return Fabric.Event$$anonymous$$anager.Instance.IsEventActive(n, null);
     }
 }
 

And here's the audio hierarchy:

alt text

ee693cfb537038db650350eb03cf158e.png (8.7 kB)
avatar image InfluxOG brunocoimbra · May 03, 2016 at 11:22 PM 0
Share

As well as this one if it helps:

alt text

a76e0c044206f1f9711a298f278457dd.png (100.4 kB)
avatar image brunocoimbra InfluxOG · May 04, 2016 at 08:50 PM 0
Share
 Fabric.Event$$anonymous$$anager.Instance.PostEvent(eventName, ob);

That line leads to another script, that may be the source of your problem.

But, that code is really redundant, creating several funcions calls just to play and audio, I believe that you can create a more efficient way to do that.

If you REALLY want to use that sound manager, post the code of your Event$$anonymous$$anager, as there is nothing wrong with what you posted until now.

avatar image NonBreaker · May 03, 2016 at 09:24 PM 0
Share

Besides the info that brunocoimbra gave, I would also recommend adding the following to see if it is registering that your player actually leaves.

 void OnTriggerExit(Collider objectCollided)
 {
     if (objectCollided.gameObject.tag == "Player")
     {
         Debug.Log("Player has left area")
     }
 }
 

Honestly I don't see why this wouldn't work unless there is something in your Audio$$anonymous$$anager script interfering.

avatar image InfluxOG NonBreaker · May 03, 2016 at 11:26 PM 0
Share

Hmm, the debug log did put out that message when I ran away, so I guess it is the audio component that's at fault.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

What is the 3D equivalent of using Physics2D.OverlapArea to check for if a character is grounded? 2 Answers

2D Platformer Character Acts Weird When Collide Side of a Platform 0 Answers

App works fine on PC but not on android 0 Answers

Rotating Gameobject not Colliding 1 Answer

Edge collider BoxCast issue 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