Hi Im hoping someone could help me work out how to bring up the fader from one end of a trigger from 0 at the edge of the trigger to 100 percent by the time you get to the middle then back down to 0 when you walk out the other side. I have drawn a diagram to try to explain what I mean.
This is what I have so far, sorry I’m not the best coder.
using UnityEngine;
using System.Collections;
using UnityEngine.Audio;
public class AudioTrigger : MonoBehaviour
{
//Audio stuff
public AudioMixer mixer;
public AudioMixerSnapshot[] snapshots;
//Box Collider stuff
public Collider audioTriggerBox;
public Bounds bounds;
private Transform centreOfBounds;
private Transform edgeOfBounds;
private float[] weights;
private Transform Player;
// Use this for initialization
void Start ()
{
//find the centre of the collider
bounds = audioTriggerBox.bounds;
centreOfBounds.position = bounds.center;
edgeOfBounds.position = bounds.extents;
}
// Update is called once per frame
void Update ()
{
weights[0] = 0.0f; //at the edge of the Collider
weights[100] = 1.0f; //In the middle of the Collider
mixer.TransitionToSnapshots(snapshots, weights , 1.0f);
//at the centre of the Bounding box
}
}
well if you want that to work as a trigger you’ll need to be using OnTriggerEnter, OnTriggerExit and OnTriggerStay…
