How do I hit multiple enemies that are moving around
Hi everyone, I'm new to unity and coding, hopefully someone can help...
I already have a raycast on hit function that kills one enemy onclick and give loots & exp and I'm trying to make a skill that can hit multiple enemies (maybe 2 and or everything, like a god skill) at the same time.
Not sure if Raycast can do it. If there is a better way, I'd love to hear it. Hope that makes sense. Thanks in advance
Here's my code :
void Update()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
BoxCollider bc = hit.collider as BoxCollider;
if (bc != null)
{
//Destroy Object
Destroy(bc.gameObject);
//Give Loots
DropLoot();
//Give Experience
foreach (GameObject go in players)
{
go.GetComponent<PlayerController>().SetExperience(expGranted / players.Length);
}
}
}
}
Your answer
Follow this Question
Related Questions
RayCastAll seemingly ignoring a particular collider 0 Answers
RaycastAll doesnt register collisions correctly. 0 Answers
How can I access more Hinge Joints? 0 Answers
Obtain a Transform using RayCastAll without a Collision (ie a point in space) 2 Answers
How do get multiple variables from different objects to test if they are true? 1 Answer