Post by AppThing on Nov 23, 2015 18:49:11 GMT
Is it possible (and if so does anyone have a sample snippet of code) initiate a raycast hit for the killable scripts? i.e. I have a Laser Turret I want to setup.. I have tried the following but it doesn't seme to be working for me for some reason:
The Debug Send Damage fires, but the Enemy does not get killed
public class AppThingTurretSystem : TurretSystem_Turret {
public DarkTonic.CoreGameKit.Killable myKillable;
public override void Start() {
base.Start ();
myKillable = GetComponent<Killable>();
}
public override void RaycastAttack()
{
RaycastHit hit;
randBarrel = Random.Range(0,muzzlePositions.Length); //pick a random barrel to fire from
if(muzzleFlash) //if there's a muzzle prefab assigned, create one
Instantiate(muzzleFlash, muzzlePositions[randBarrel].position, muzzlePositions[randBarrel].rotation);
if(Physics.Raycast(muzzlePositions[randBarrel].position, muzzlePositions[randBarrel].forward, out hit, shotRange, obstaclesLayerMask)) //casting a ray, and ignoring the RangeCollider
{
GameObject hitGO = hit.collider.transform.root.gameObject;
if(hitGO.tag == enemyTag) //if the hit object tag matches our enemy tag, deal damage to it
{
hitGO.GetComponent<TurretSystem_Health>().TakeDamage(damageAmount);
Debug.Log("Enemy Hit");
KillOrDamage(hitGO);
}
if(hitGO.tag == secondaryEnemyTag && shootSecondaryToo)
{
hitGO.GetComponent<TurretSystem_Health>().TakeDamage(damageAmount);
Debug.Log("2nd Enemy Hit");
KillOrDamage(hitGO);
}
if(hit.collider && hitSpark) //if we assigned a hitSpark, create one at the hit point
{
Instantiate(hitSpark, hit.point, Quaternion.identity);
}
}
if(useAmmo) //you'll see this a few times in the script. if we checked that we're using ammo, spend it
{
clipSize-=1; //deduct one bullet per shot
if(clipSize <= 0) //if theres no more bullets in the clip
Reload(); //reload
}
}
private void KillOrDamage(GameObject go)
{
if(!myKillable) myKillable = GetComponent<Killable>();
var kill = go.GetComponent<Killable>();
if (kill == null) {
return;
}
Debug.Log("Send Damage = "+ myKillable.atckPoints.Value);
kill.TakeDamage(myKillable.atckPoints.Value, myKillable);
return;
}
}
The Debug Send Damage fires, but the Enemy does not get killed
