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 Sethas123 · Oct 10, 2019 at 03:21 PM · raycasthitforeachfmod

foreach raycast hit fmod parameter -0.2 f?

I got a slider which deactivate and activates different walls, so you can set the amount of walls. Through the walls is called a raycast with the foreach function. I want to achieve that for every hit fmod parameter decrease 0.2f volume and if you deactivate the wall it will increase, like occlusion. For now i got it work with a integer (hitcount) that count the hits and on the release of the slider it resets. Everytime you release the slider CallRaycast() is called. This works, but doesnt work if there are more raycasts with all a different amount of hits. There need to be an update function which calls the hits?? (it doesnt work with a simple count ++ function. because it doesn't notice if there is a wall deactivated.) using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;

 public class SoundCast : MonoBehaviour
 {
     [Header("FMOD Event")]
     [FMODUnity.EventRef]
     public string SelectAudio;
     FMOD.Studio.EventInstance Audio;
     FMOD.Studio.PARAMETER_ID Volume;
     FMOD.Studio.PARAMETER_ID LPF;
     GameObject player;
     FMOD.Studio.EventInstance Sound;
     //public float position;
     public float maxRayDistance = 30;
     public LayerMask activeLayers;
     public GameObject Target;
     public static int hitCount;
 
     void Start()
     {
         player = GameObject.FindGameObjectWithTag("Player");
 
         Sound = FMODUnity.RuntimeManager.CreateInstance(SelectAudio);
         Sound.start();
         Sound.setParameterByName("LPF", 22000f);
         Sound.setParameterByName("Volume", 1f);
     }
 
     private void Update()
     {
         FMODUnity.RuntimeManager.AttachInstanceToGameObject(Sound, GetComponent<Transform>(), GetComponent<Rigidbody>());
     }
 
     public void CallRaycast()
     {
         Vector3 direction = (Target.transform.position - transform.position).normalized;
         Ray ray = new Ray(transform.position, direction);
         RaycastHit[] hits = Physics.RaycastAll(ray, maxRayDistance, activeLayers);
 
 
         //Debug.DrawLine(transform.position, direction * maxRayDistance, Color.red);
         foreach (RaycastHit hit in hits)
         {
 
             //Debug.DrawLine(hit.point, hit.point + Vector3.up * 5, Color.green);
             hitCount += 1;
 
             Debug.Log(hitCount);
 
         }
         if (hitCount == 0)
         {
             Sound.setParameterByName("LPF", 22000f);
             Sound.setParameterByName("Volume", 1f);
         }
         if (hitCount == 1)
         {
             Sound.setParameterByName("LPF", 19000f);
             Sound.setParameterByName("Volume", 0.85f);
         }
         if (hitCount == 2)
         {
             Sound.setParameterByName("LPF", 16000f);
             Sound.setParameterByName("Volume", 0.7f);
         }
         if (hitCount == 3)
         {
             Sound.setParameterByName("LPF", 13000f);
             Sound.setParameterByName("Volume", 0.55f);
         }
         if (hitCount == 4)
         {
             Sound.setParameterByName("LPF", 10000f);
             Sound.setParameterByName("Volume", 0.4f);
         }
         if (hitCount == 5)
         {
             Sound.setParameterByName("LPF", 7000f);
             Sound.setParameterByName("Volume", 0.25f);
         }
     }
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

183 People are following this question.

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

Related Questions

Foreach working very strange 0 Answers

Abrupt parameter change with fmod integration 0 Answers

Raycast to multiple objects 2 Answers

Trigger and Rotation Issue 0 Answers

In a object where to use raycasting? 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