public var TiempoDestruccion : float = 10;

public var Aceleracion : float = 1;
public var UseRotation : boolean = false;
public var ProyectilAutoRotacion : boolean = false;
public var VelocidadRotacion : Vector3 = Vector3 (2, 2, 2);
public var Damage : int = 45;

public var RatioDeDisparo : float = 1;

public var SplashObject : GameObject;
public var Decall : GameObject;

function Start () {
	Destroy(this.gameObject, TiempoDestruccion);
}

function Update () {
	if(ProyectilAutoRotacion == true){
		transform.Rotate(Vector3.right, VelocidadRotacion.x, Space.World);
		transform.Rotate(Vector3.up, VelocidadRotacion.y, Space.World);
		transform.Rotate(Vector3.forward, VelocidadRotacion.z, Space.World);
	}

}

function OnCollisionEnter (other : Collision) {
	// Crea el splash al detectar el impacto (la colision)
	// Rota el objeto para que tenga la direccion de la normal
	if(other.transform.tag == "Player")
		GeneralVars.nSalud -= Damage;
	else
	if(other.transform.tag == "Enemy"){
		var EstadoEnemigo : ManageEnemyStatus = other.gameObject.GetComponent(typeof(ManageEnemyStatus));
		EstadoEnemigo.Health -= Damage;
	}
	else
	if(other.transform.tag != "Armas"){
		var contacto : ContactPoint = other.contacts[0];
		var pos : Vector3 = contacto.point;
		var rot : Quaternion = Quaternion.identity;
		if(UseRotation == true)
			rot = Quaternion.FromToRotation(Vector3.forward, contacto.normal);
		if(SplashObject != null)
			var MySplashObj : GameObject = Instantiate(SplashObject, pos, rot);
		if(other.transform.renderer != null){
			var MyColor : Color = other.transform.renderer.material.color;
			var MyParticleColor : ParticleChangeColor = MySplashObj.GetComponent(typeof(ParticleChangeColor));
			MyParticleColor.MyColor = MyColor;
		}
			
		// Creo un decall.
		var rotDecall : Quaternion= Quaternion.FromToRotation(Vector3.up, contacto.normal);
		var DecallObj : GameObject = Instantiate(Decall, pos, rotDecall);
		DecallObj.transform.parent = other.transform;
		DecallObj.transform.localPosition.y += 0.1;
	}
	
	// Destruye la bala ahora mismo.
	Destroy (gameObject);
}
