1
votes

Well my question as it says refer to particle Systems and sounds, i am not 100% secure that it is related to the fact that is the particle system, basicly i have fire on my game, and when my ball colides with the fire it should play the sound, the thing is that it can't find the AudioSource and keep saying that is no AUdioSource attached, but i already did it using 2 diferent ways, attaching the audioSource through inspector, and setting it to private and get the component of the audioSOurce in the gameObject, so what am i doing wrong? :S

Here is the code:

using UnityEngine;
using System.Collections;

public class particlCol : MonoBehaviour {

    Manager gameManager;
    public AudioClip aud;
    private AudioSource audioC;

    void Start()
    {
        audioC = GetComponent<AudioSource> ();
        gameManager = GameObject.Find ("GameController").GetComponent<Manager> ();
    }

    void OnParticleCollision(GameObject other)
    {

        if (other.tag == "Player") {
            Debug.Log ("entrou");
            audioC.clip = aud;
            audioC.Play ();
            gameManager.LifeDown ();
        }
    }
}

Screenshot of the object:

screenshot

Ps: it worked perfectly before, when it touched the fire i lost a life in my game so the problem is not with the colision itself

2
Where is your AudioSource located as a component? Which object? Can you show us a screenshot of the hierarchy and the properties of the objects involved? - Serlite
it is attached to the same gameobject, i have the script on the particlegameobject but i put a screenshot 2 min - user7421853

2 Answers

1
votes

You can do one thing:

Create a gameObj, take that audio which u wanna play to hierarchy , uncheck the play on awake property and them make it a child of the above gameObject.

then create a script and in that script make AudioSource variable and in Start() do: //example

public AudioSource shoot;

Start(){

shoot=GetComponent();

}

//thats it

Now attach this script to the above made GameObject and attach ur sound file which was the child to the script AudioSource variable option(which will otherwise show none) .

Now wherever u wanna make that sound to play u just have to call that script(

0
votes

Check in Awake method is your AudioSource null something like this:

  void Awake()
 {
     Debug.Log("AudioSource: " + GetComponent<AudioSource>());
 }

Or try with:

[RequireComponent(typeof(AudioSource))]

And I read that bug can be caused by audio clip so try to reimport your sound.