Post by kingmob on Sept 12, 2018 23:36:21 GMT
Hi I'm trying to fire a raycast and then do the takeDamage method on said killable. My programming knowledge is not very good but I've beat my head against the keyboard enough to feel justified in asking.
That's the code I'm working with now, I'm assuming it's something easy so I appreciate anyone smarter than me taking a look!
Thanks!
public void FireSingleShot()
{
TriggerAudioSource.PlayOneShot(TriggerAudioSource.clip);
TriggerParticleSystem.Play();
RaycastHit hit;
Vector3 origin = TriggerParticleSystem.transform.position;
Vector3 direction = TriggerParticleSystem.transform.forward;
if (Physics.Raycast(origin, direction, out hit, 100f))
{
hitObject = hit.collider.gameObject;
hitObjectKillable = hit.GetComponent<Killable>;
if (hitObject.CompareTag("Enemy")) // TAG OF WHAT YOU ARE TRYING TO SHOOT
{
int damageToDeal = 1;
//ENEMY EnemyScript = hitObject.GetComponentInParent<ENEMY>();
// Determine_Damage();
//EnemyScript.Hurt(CurrentDamage);
hitObjectKillable.TakeDamage(damageToDeal);
//Killable.TakeDamage(damageToDeal, hitObjectKillable);
Quaternion rot = Quaternion.FromToRotation(Vector3.forward, hit.normal);
Instantiate(EnemyScript.WoundParticleSystem, hit.point, rot);
}
else
{
Quaternion rot = Quaternion.FromToRotation(Vector3.forward, hit.normal);
Instantiate(SparkParticleSystem, hit.point, rot);
}
}
print("Pew!");
}
That's the code I'm working with now, I'm assuming it's something easy so I appreciate anyone smarter than me taking a look!
Thanks!