Question by
Leemeoyi · Aug 27, 2019 at 09:58 PM ·
scripting problemscript.
Multiple Raycast on a melee weapon detect multiple of times.,Multiple raycast melee detect and run multiple times.
Hey guys, is anyone here experienced with raycast on melee weapon? I've made a multiple raycast (7 nodes) with list and for loop function. Now here's the problem, whenever my character swing his sword, it detect all 7 raycast and hit the collider 7 times. How do I make the collider to detect the raycast only once without disabling it's collider? And here's the script I'm attaching
IEnumerator RaycastHit()
{
while (true)
{
if (isDamage)
{
List<Vector3> nodes1 = new List<Vector3>();
for (int I = 0; I < nodes.Length; I++)
{
nodes1.Add(nodes[I].transform.position);
}
yield return new WaitForEndOfFrame();
for (int I = 0; I < nodes.Length; I++)
{
Ray ray = new Ray(nodes1[I], nodes[I].transform.position - nodes1[I]);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, (nodes[I].transform.position - nodes1[I]).magnitude))
{
if (hit.transform.tag == "Enemy")
{
hit.transform.SendMessage("Damage", dmg);
}
}
Debug.DrawLine(nodes1[I], nodes[I].transform.position, new Color(255, 0, 0), 0.3f, false);
}
}
else
{
yield return new WaitForEndOfFrame();
}
}
}
Comment
Your answer

Follow this Question
Related Questions
Script error and no Variables showing 0 Answers
Saving doesn't work after Build 0 Answers
How to create a script for a vehicle fuel? 0 Answers
ArgumentOutOfRangeException is occuring when it shouldn't 0 Answers
Manual GUI Refresh 0 Answers