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);
}
}
Your answer
Follow this Question
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