var theLight : Light;
function OnTriggerEnter ()
{
theLight.enabled = true;
}
-------
if (hit.collider.isTrigger == true) {
hit.collider.active = false;
yield WaitForSeconds (0.1);
hit.collider.active = true;
}
5/10/2010
Controlling music loops
/*
Groove v1.1 © "hai_ok". Feel free to use for anything.
If you use this, please let me know. Its good to know if I helped someone. :D
INSTRUCTIONS:
Use this script to dynamically change the music in a game, in the middle of any "song".
It only works with loops that you might use to make music in music creation software like Garageband or FL Studio (Techno EJ...).
This only assumes you want to use bass and drum tracks.
I did this so that I could use more prominant lead loops to "celebrate" getting collectibles or acheiving goals.
You can Add AS MANY LOOPS AS YOU NEED from within the Unity Inspector once you have added the script to the Raideo.
Audition them to see where you would put them.
Try to keep them in groups that maintain the same mood.
Or switch to a funkier set of loops to "punctuate" a win.
THE ORDER OF EVENTS IN THIS SCRIPT IS VITAL TO ITS FUNCTION = DO NOT CHANGE THIS WITHOUT KNOWING WHAT YOU'RE DOING:
This was written to call from another script.
Here is the Syntax:
groove.tune("set","dance");}
groove.tune("set","triphop");}
groove.tune("set","off");}
*/
// Make sure that "Play On Awake" is on, and "Loop" is off, for your Audio Source.
private var triphopdelay : float = 4.8; // length of the triphop loops
private var dancedelay : float = 3.692; // length of the dance loops
var triphopDrumLo : AudioClip[];//Lo triphop Drum Loop Array
var triphopBassLo : AudioClip[];//Lo triphop Bass Line Array
var danceDrumLo : AudioClip[];//Hi triphop Drum Loop Array
var danceBassLo : AudioClip[];//Hi triphop Bass Line Array
/*create a one dimensional array where the name is an int from 0-infinity and I and inject my own values*/
static var music = new Array();/*the array is calle music and is accesable as groove.music[x] where x = the int entry value*/
static var station:String;/*the big ticket*/
function Awake () {//prep stuff here so other stuff can use it
tune("set","off");//tune the raideo off
}
function Start(){/*00*/
while (true) {/*crack smoker*//*which is to say, "hard worker", or always on the job. ;) */
station=tune("get","tune");/*call the music array and get the station*/
switch (station){/*evaluate the station*/
case "triphop":/*Play a random pair of drum and bass loops from any selection in their entire arrays*/
audio.PlayOneShot(triphopDrumLo[Random.Range(0,triphopDrumLo.Length)]);
audio.PlayOneShot(triphopBassLo[Random.Range(0,triphopBassLo.Length)]);
yield WaitForSeconds (triphopdelay);/*wait for the loops to play themselves thru*/
break;
case "dance":/*Play a random pair of drum and bass loops from any selection in their entire arrays*/
audio.PlayOneShot(danceDrumLo[Random.Range(0,danceDrumLo.Length)]);
audio.PlayOneShot(danceBassLo[Random.Range(0,danceBassLo.Length)]);
yield WaitForSeconds (dancedelay);/*wait for the loops to play themselves thru*/
break;
case "off":
yield WaitForSeconds (2);//wait to see if they turn me back on
break;
}
}
}
/*---TUNE THE RAIDEO-----------------------------------------------------------------*/
static function tune (instruction:String,value:String){
if ("set" in instruction){/*if we are changing the station*/
music.Clear();/*empty the array*//*we're only storing whats on so we dont need anything else*/
music.Add(value);/*inject the value as the first entry (stored at the [0] index)*/
//Debug.Log (">>>GETTING TIRED OF "+station+". TIME FOR SOME "+value+".<<<");/*tell teh player what we did*/ }else if ("get" in instruction){/*if we are retreiving the station*/ value=music[0];/*assign the value to the first array entry (stored at the [0] index)*/ return value;/*return the value*/ } } /* >>>THE ORDER OF EVENTS IN THIS SCRIPT IS VITAL TO ITS FUNCTION<<< instance =" Instantiate(prefab);" velocity =" Random.insideUnitSphere">
Communication between scripts
var playerHealth : NameOfGUIScript; //This will become a link to your player health.
function Start () {
playerHealth = FindObjectOfType(NameOfGUIScript); //This caches a link to that script.
}
function OnCollisionStay (collision : Collision) {
if (collision.relativeVelocity.magnitude > 0.1) {
playerHealth.health += 1; //Find the variable health in the script we found earlier and add 1 to it.
}
}
function Start () {
playerHealth = FindObjectOfType(NameOfGUIScript); //This caches a link to that script.
}
function OnCollisionStay (collision : Collision) {
if (collision.relativeVelocity.magnitude > 0.1) {
playerHealth.health += 1; //Find the variable health in the script we found earlier and add 1 to it.
}
}
Subscribe to:
Posts (Atom)