- Home /
GetComponent ? help!
Well i have one enemy prefab, when my bullet impact with the enemy, he drop a blood prefab .. BUT when i have 2 or more enemys, only drop the blood one enemy ... no matter who the enemy is, only one drop the blood prefab ... I read somewhere something about GetComponent but I dont know how to use with GameObject ... any help?
Enemy script:
var elTarget : Transform;
var sangrePrefab : Transform;
var DistanciaDelJugador = 2;
var DistanciaDelTrigger = 2;
var velocidad = 5;
var modeloMuerto : GameObject;
var golpeando = 0;
static var vida = 100;
static var sangrando = false;
static var saludPlayer = 0;
private var siguiendo = 1;
private var pausado = 0;
function Start()
{
animation.wrapMode = WrapMode.Loop;
animation.Play("cacoCorre");
}
function DestinoCaco()
{
destination = elTarget.position;
destination.y = transform.position.y;
pausado = 1;
return destination;
}
function Update()
{
if (siguiendo == 1 && saludPlayer == 0)
{
if ((elTarget.position - transform.position).magnitude <= DistanciaDelJugador)
{
siguiendo = 0;
pausado = 1;
animation.CrossFade("cacoPega", 0.2);
}
else
{
transform.forward = DestinoCaco() - transform.position;
transform.Translate(Vector3.forward * velocidad * Time.deltaTime);
}
}
else if (pausado == 1 && saludPlayer == 0)
{
distance = (transform.position - DestinoCaco()).magnitude;
if (distance > DistanciaDelTrigger)
{
siguiendo = 1;
pausado = 0;
animation.CrossFade("cacoCorre", 0.2);
}
}
if (sangrando)
{
sangrando = false;
Sangre();
}
if (animation.IsPlaying("cacoPega"))
{
if(golpeando == 0)
{
golpeando = 1;
saludJugador.salud -=1;
StartCoroutine(SacandoVida());
}
}
if (vida <=0)
{
sndBardeada.habla = true;
Destroy(gameObject);
Instantiate(modeloMuerto, transform.position, transform.rotation);
}
if (saludPlayer == 1)
{
print("Player dead");
}
}
function Sangre()
{
Instantiate(sangrePrefab, transform.position, transform.rotation);
}
function SacandoVida()
{
yield WaitForSeconds(1);
golpeando = 0;
}
Bullet Impact:
//var distance : float = 0.2; //var sangrePrefab : GameObject; var script : conPalo; script = GetComponent("conPalo");
function Update() { var dir = transform.TransformDirection(Vector3.forward); var hit : RaycastHit;
Debug.DrawRay(transform.position, dir * 0.5, Color.red);
if (Physics.Raycast(transform.position, dir, hit, 0.5))
{
if (hit.collider.gameObject.tag == "Enemigo")
{
Destroy(gameObject);
colorHit.hiteamos = true;
script.vida -=10;
script.sangrando = true;
}
}
}
When variable "sangrando" is TRUE, enemy drop the blood prefab ... but only 1 enemy drop ... no matter who the enemy is
When variable "sangrando" is TRUE, enemy drop the blood prefab ... but only 1 enemy drop ... no matter who the enemy is
Answer by DaveA · May 03, 2011 at 06:28 AM
I read this article but dont know how to implement in my script, can u help me?
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
create GUI.Label and then access to it.. 2 Answers
[JS] - GetComponents (No appropriate version) 1 Answer
How can I access an inherited method from a separate (collided) object? 1 Answer