Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

No sound on collision - Simple problem

Discussion in 'Audio & Video' started by lukedeane, Nov 6, 2015.

  1. lukedeane

    lukedeane

    Joined:
    Nov 6, 2015
    Posts:
    1
    Hi everyone,

    I'm new at Unity, but i've tried many different options for this which would not compile. Currently, this .js will sit happily on my object:


    #pragmastrict


    public var Xylo_13: AudioClip;
    var audi: AudioSource;

    function Start() {
    audi = GetComponent.<AudioSource>();
    audi.PlayOneShot(Xylo_13, 0.7F);
    }

    function Update () {

    }



    However, this is simply an elaborate way of saying "play on awake". I included a screen-shot; where you can see that the inspector shows the audio source (Audi) and also has a space for the "sound" itself (Xylo_13), although that is already attached to the object so I'm not sure why it's there.

    Could someone help me to modify this code so that it plays when the player collides with the object? I'm making a space where you can jump diagonally up a piano keyboard and I want it to trigger piano sounds.

    One other issue is that I do not want to set my Mesh Collider to convex, so I can't select "is trigger".

    Sorry to post such a basic question; I have visited the "playoneshot" Unity manual page and tried the example code but no matter how hard I try I can't get this to work.
     

    Attached Files:

  2. agusmao

    agusmao

    Joined:
    Oct 25, 2015
    Posts:
    2