Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-1106· OpenAIHugging Face Arena Human Preference 55K

Please combine these two scripts into one that I can attach onto a Particle System in…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with gpt-4-1106-preview’s answer.
  1. User

    Please combine these two scripts into one that I can attach onto a Particle System in Unity:

    using UnityEngine; using UnityEngine.Audio;

    public class AudioSpectrum : MonoBehaviour { public AudioMixer mixer; private float[] _samples = new float[512]; // Size can be adjusted based on your needs

    void Update()
    {
        // Get the data from the Audio Mixer
        mixer.SetFloat("MusicVol", Mathf.Log10(GetComponent<AudioSource>().volume) * 20);
        GetComponent<AudioSource>().GetSpectrumData(_samples, 0, FFTWindow.Blackman);
        // Now _samples will hold the spectrum data which can be used to drive the particle system
    }
    
    // This function can be used to get the specific frequency band value
    public float GetBandValue(int band)
    {
        if (band >= 0 && band < _samples.Length)
        {
            return _samples[band];
        }
        return 0f;
    }
    

    }

    The first script worked and was able to compile. This is the second script, which didn't work. I'd like to embed this script within the previous script, so that I can adjust settings for the particle system's audio responsivity (fade etc) via Inspector: using UnityEngine;

    public class ParticleController : MonoBehaviour { public ParticleSystem particleSystem; public AudioSpectrum audioSpectrum;

    private ParticleSystem.MainModule mainModule;
    
    void Start()
    {
        mainModule = particleSystem.main;
    }
    
    void Update()
    {
        float bandValue = audioSpectrum.GetBandValue(1); // Use the appropriate band
    
        // Adjust particle size
        mainModule.startSize = Mathf.Lerp(mainModule.startSize.constant, bandValue * 2, Time.deltaTime);
    
        // Adjust color
        mainModule.startColor = Color.Lerp(Color.blue, Color.red, bandValue);
    
        // Adjust emission rate
        var emission = particleSystem.emission;
        emission.rateOverTime = bandValue * 100;
    
        // Adjust other properties as needed
    }
    

    }

  2. Assistant

    Here's the combined script that you can attach to a Particle System in Unity:

    using UnityEngine;
    using UnityEngine.Audio;
    
    public class AudioSpectrum : MonoBehaviour
    {
        public AudioMixer mixer;
        public ParticleSystem particleSystem;
        
        private float[] _samples = new float[512]; // Size can be adjusted based on your needs
        private ParticleSystem.MainModule mainModule;
    
        void Start()
        {
            mainModule = particleSystem.main;
        }
    
        void Update()
        {
            // Get the data from the Audio Mixer
            mixer.SetFloat("MusicVol", Mathf.Log10(GetComponent<AudioSource>().volume) * 20);
            GetComponent<AudioSource>().GetSpectrumData(_samples, 0, FFTWindow.Blackman);
            // Now _samples will hold the spectrum data which can be used to drive the particle system
    
            float bandValue = GetBandValue(1); // Use the appropriate band
    
            // Adjust particle size
            mainModule.startSize = Mathf.Lerp(mainModule.startSize.constant, bandValue * 2, Time.deltaTime);
    
            // Adjust color
            mainModule.startColor = Color.Lerp(Color.blue, Color.red, bandValue);
    
            // Adjust emission rate
            var emission = particleSystem.emission;
            emission.rateOverTime = bandValue * 100;
    
            // Adjust other properties as needed
        }
    
        // This function can be used to get the specific frequency band value
        public float GetBandValue(int band)
        {
            if (band >= 0 && band < _samples.Length)
            {
                return _samples[band];
            }
            return 0f;
        }
    }
    

    In this combined script, both AudioSpectrum and ParticleController functionalities are integrated into one script. You can attach this script to a GameObject in your Unity scene and assign the Audio Mixer, Particle System, and other settings through the Inspector.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.