Hello
Can someone help me with a codeing problema plz? i am trying to modify the baby's shotting tutorial to use bombs, and im having problem with the overlapSphere Enemyhealth detection, i can see throw log print (image down) that i get Enemies colliders, but i cant acces to the script to make damage
I used the normal tutorial Raycast code:
//////////////////////////////////////////////////////
if(Physics.Raycast (shootRay, out shootHit, range, shootableMask))
{
// Try and find an EnemyHealth script on the gameobject hit.
EnemyHealth enemyHealth = shootHit.collider.GetComponent ();
// If the EnemyHealth component exist...
if(enemyHealth != null)
{
// ... the enemy should take damage.
enemyHealth.TakeDamage (damagePerShot, shootHit.point);
}
////////////////////////////////////////////////
Modified to use in the bomb explosion script like this:
///////////////////////////////////////////////
var hitColliders = Physics.OverlapSphere(transform.position, 50);
for (var i = 0; i < hitColliders.Length; i++)
{
Debug.Log(hitColliders[i]); /// This is the print of the image
EnemyHealth enemyHealth = hitColliders[i].GetComponent();
// If the EnemyHealth component exist...
if(enemyHealth != null)
{
Debug.Log("Le hace daño");
// ... the enemy should take damage.
enemyHealth.TakeDamage_sin_vector (9999);
}
}
///////////////////////////////////////////////////////
But the if is not validated
I tried also with:
//////////////////////////////////////////////////////
EnemyHealth enemyHealth = hitColliders[i].GetComponent().GetComponent();
/////////////////////////////////////////////////////
but i get same result :S
Tnks
