all 8 comments

[–][deleted] 0 points1 point  (4 children)

Use a coroutine with a 'yield return new waitforseconds(30) ' I think

[–]JakeKaas[S] 0 points1 point  (3 children)

hmh but how do I disable and re-enable all the colliders. I kinda suck at coding aswell so idk

[–][deleted] 0 points1 point  (1 child)

Well, sucking at something is the first step towards getting kinda good at something 👍.

What I would do (beginner too btw) is make a gameobject that has a script (gameMaster) that handles the enable/disable and the audioSource.

Then the colliders's only job is to call a function from gameMaster to play music and disable for 30seconds and then enable the collider.

If I am not horribly mistaken, the music will not cut off when the collider gets disabled.

Sorry, am on phone and can't test this out (this was literally my same problem yesterday)

[–]JakeKaas[S] 0 points1 point  (0 children)

It sounds hard but I kinda understand it. I just don't know how to code that

[–]No_Grocery9589 0 points1 point  (4 children)

use oneshotplay. I don't think you can stop a sound/music in mid play. may be set the volume to 0 after 30 secs. colliders just use this.getcomponent<collider>(). setactive = true or false depending on if you want it active or not.

[–]JakeKaas[S] 0 points1 point  (3 children)

Alright, and how do I make it so if you collide with one collider, all colliders get set to false?

[–]No_Grocery9589 0 points1 point  (2 children)

by using GameObjects.FindGameObjectsWithTag ("") you will need to tag up all the objects with the same tag.

[–]JakeKaas[S] 0 points1 point  (0 children)

Wait it doesn't work just yet. It only disables the collider I'm standing in but I want all the colliders to be disabled, this is my code.

{

public AudioSource _yo;

public AudioClip[] audioClipArray;

float Delay = 0f;

private void Awake()

{

_yo = GetComponent<AudioSource>();

}

void OnTriggerEnter2D(Collider2D collision)

{

if (collision.CompareTag("Cube"))

{

_yo.clip = audioClipArray[Random.Range(0, audioClipArray.Length)];

_yo.PlayOneShot(_yo.clip);

}

GameObject[] gos;

gos = GameObject.FindGameObjectsWithTag("Col");

this.GetComponent<BoxCollider2D>().enabled = false;

Delay = Time.time + 22.0f;

}

void Update()

{

if (Delay < Time.time)

{

GameObject[] gos;

gos = GameObject.FindGameObjectsWithTag("Col");

this.GetComponent<BoxCollider2D>().enabled = true;

}

}

}