Glass Beads

I was tasked with making a chain out of musical beads. I wanted users to be able to engage with this in a playful manner. I found it important for users to instantly be interested in the beads and to engage with them. Furthermore I wanted the interaction with them to feel natural. Here's a video that demonstrates it (turn on your sound):

I made the bead chains by using the Unity hinge joint component and adding the previous bead as the linked object. The first bead is has a kinematic rigidbody without gravity so the chain will stay in place.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(AudioSource))]

public class GlassCollision : MonoBehaviour
{
    [SerializeField]
    private AudioClip[] audioClips;
    AudioSource audioData;
    private float minPitch = .75f;
    private float maxPitch = 1.5f;

    void Start()
    {
        audioData = GetComponent<AudioSource>();
    }

    private void OnCollisionEnter(Collision collision)
    {
        int randomClipIndex = (int)Random.Range(0, audioClips.Length - 1);
        float randomPitch = Random.Range(minPitch, maxPitch);

        audioData.pitch = randomPitch;

        audioData.clip = audioClips[randomClipIndex];
        audioData.Play(0);
    }
}

Last updated

Was this helpful?