//ENG: this scripts let you instantiate continuosly objects (sparks per example). you must attach this script to an object with rigidbody
//ESP: este script te permite instanciar continuamente objetos (chispas, por ejemplo). debes adjuntar este script a un objeto con rigidbody
var Sparks:GameObject; //ENG: the object that you wanna instance
//ESP: el objeto que quieres instanciar
var timerate = 0.1; //ENG: time rate that is instanced the object
//ESP: ratio de tiempo en el que el objeto es instanciado
private var nextinstance=0.0;
function OnCollisionStay(collision : Collision)
{
var contact = collision.contacts[0];
var rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
var pos = contact.point;
//ENG:When the magnitude is higher and the rate is over, instance again
//ESP: cuando la magnitud del impacto es alta y el ratio se acaba, instancia otra vez
if(collision.relativeVelocity.magnitude > 0.1 && Time.time>nextinstance)
{
nextinstance = Time.time + timerate;
Instantiate(Sparks, pos, rot);
}
}
//ENG: This scripts emit particles and flick a light when you push certain button. attach it to an controlable game object with a light and particle emmiter game component
//ESP: este script hace emitir particulas y hacer parpadear una luz cuando pulsas cierto boton, adjuntalo a un objeto controlable con componente de emisor de particulas y componente de luz
var jetsound:AudioClip; //ENG:The sound clip
//ESP: el clip de sonido
var soundrate : float = 0.02;//ENG: sound playing ratio
//ESP: ratio de emitir sonido
private var nextsound = 0.0; //ENG: time left to play next sound
//ESP: timpo que queda para reproducir el siguiente sonido
var duration = 1.0; //ENG: light flickering duration
//ESP: duración de la luz parpadeante
function Update () {
//ENG: if you push up, emit particle and start to flick the light intensity, else, stop emmiting particles and put light intensity to 0
//ESP: si pulsas arriba, emite particulas y empieza a parpadear la intensidad de la luz, si no, para de emitir particulas y pone la intensidad de la luz a 0
if(Input.GetAxis("Vertical") > 0)
{
particleEmitter.emit = true;
var phi = Time.time / duration * 2 * Mathf.PI;
var amplitude = Mathf.Cos( phi ) * 0.5 + 0.5;
light.intensity = amplitude*3;
if(Time.time > nextsound)
{
//ENG: play audio clip
//ESP: reproducir el clip de audio
if(jetsound)
audio.PlayOneShot(jetsound);
nextsound = Time.time + soundrate;
}
}
else
{
particleEmitter.emit = false;
light.intensity = 0;
}
}