Hey so im creating a game where there is going to be alot of enemies and i use raycast for my melee weapon right now im checking the hit collider tag but that will make a big script if i should do it on every enemy so how should i do it? this is how i do it right now
private void DoAttack()
{
Ray ray = playingCam.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, myWeapon.attackRange))
{
myWeapon.attackDamage = Random.Range(myWeapon.minAttackDamage, myWeapon.maxAttackDamage);
if (hit.collider.tag == "StoneGolem")
{
StoneGolemController eHealth = hit.collider.GetComponent();
eHealth.TakeDamage(myWeapon.attackDamage);
Debug.Log(myWeapon.attackDamage);
}
}
}
↧