i am making a game where i need to bounce a lazzer off of mirrors and i cant get the line renderer points where i want them
here is what my sceen looks like i am using raycasts and detecting what they hit to determine if it hits a mirror or not and what angel of mirror i hit then set the line renderer points from thoes
i know the rays are right because i used debug.line to show where the rays are
and i dont know why my line renderer points are wrong
here is the script i wrote
using UnityEngine;
using System.Collections;
public class lazzer : MonoBehaviour
{
LineRenderer line;
private int numlazzerpoints=2;
private int direction=1;
private Vector3[] lazzerpoints=new Vector3[1];
private Ray lazzerrays;
private RaycastHit hit;
// Use this for initialization
void Start ()
{
numlazzerpoints=2;
lazzerpoints[0] =transform.position;
line = gameObject.GetComponent<LineRenderer>();
line.SetVertexCount (numlazzerpoints);
line.SetPosition (0,transform.position);
}
// Update is called once per frame
void FixedUpdate ()
{
for (int count = 0; count < numlazzerpoints; count++)
{
if(direction==0)
{
if (Physics.Raycast(lazzerpoints[count], Vector3.right, out hit,20)&& hit.transform.tag == "mirror1")
{
numlazzerpoints=numlazzerpoints+1;
System.Array.Resize(ref lazzerpoints,numlazzerpoints);
line.SetVertexCount (numlazzerpoints);
lazzerpoints[count+1]=(hit.point);
line.SetPosition (count+1, hit.point);
Debug.DrawLine(lazzerpoints[count],hit.point, Color.red,500);
direction=1;
}
else if (Physics.Raycast(lazzerpoints[count],Vector3.right,out hit)&& hit.transform.tag == "mirror2")
{
numlazzerpoints=numlazzerpoints+1;
System.Array.Resize(ref lazzerpoints,numlazzerpoints);
line.SetVertexCount (numlazzerpoints);
lazzerpoints[count+1]=(hit.point);
line.SetPosition (count+1, hit.point);
Debug.DrawLine(lazzerpoints[count],hit.point, Color.yellow,500);
direction=3;
}
else
{
if (Physics.Raycast (lazzerpoints[count],Vector3.right, out hit)&& hit.transform.tag != "mirror2"&& hit.transform.tag != "mirror1")
{
lazzerpoints[1]=(hit.point);
Debug.DrawLine(lazzerpoints[count],hit.point, Color.blue,500);
line.SetPosition (count+1, hit.point);
}
}
Debug.Log(hit.point +" hit.point"+count);
}
if(direction==1)
{
if (Physics.Raycast(lazzerpoints[count], Vector3.forward, out hit,20)&& hit.transform.tag == "mirror1")
{
numlazzerpoints=numlazzerpoints+1;
System.Array.Resize(ref lazzerpoints,numlazzerpoints);
line.SetVertexCount (numlazzerpoints);
lazzerpoints[count+1]=(hit.point);
line.SetPosition (count+1, hit.point);
Debug.DrawLine(lazzerpoints[count],hit.point, Color.red,500);
direction=0;
}
else if (Physics.Raycast(lazzerpoints[count],Vector3.forward,out hit)&& hit.transform.tag == "mirror2")
{
numlazzerpoints=numlazzerpoints+1;
System.Array.Resize(ref lazzerpoints,numlazzerpoints);
line.SetVertexCount (numlazzerpoints);
lazzerpoints[count+1]=(hit.point);
line.SetPosition (count+1, hit.point);
Debug.DrawLine(lazzerpoints[count],hit.point, Color.yellow,500);
direction=2;
}
else
{
if (Physics.Raycast (lazzerpoints[count],Vector3.forward, out hit)&& hit.transform.tag != "mirror2"&& hit.transform.tag != "mirror1")
{
lazzerpoints[1]=(hit.point);
Debug.DrawLine(lazzerpoints[count],hit.point, Color.blue,500);
line.SetPosition (count+1, hit.point);
}
}
Debug.Log(hit.point +" hit.point"+count);
}
if(direction==2)
{
if (Physics.Raycast(lazzerpoints[count], Vector3.left, out hit,20)&& hit.transform.tag == "mirror1")
{
numlazzerpoints=numlazzerpoints+1;
System.Array.Resize(ref lazzerpoints,numlazzerpoints);
line.SetVertexCount (numlazzerpoints);
lazzerpoints[count+1]=(hit.point);
line.SetPosition (count+1, hit.point);
Debug.DrawLine(lazzerpoints[count],hit.point, Color.red,500);
direction=3;
}
else if (Physics.Raycast(lazzerpoints[count],Vector3.left,out hit)&& hit.transform.tag == "mirror2")
{
numlazzerpoints=numlazzerpoints+1;
System.Array.Resize(ref lazzerpoints,numlazzerpoints);
line.SetVertexCount (numlazzerpoints);
lazzerpoints[count+1]=(hit.point);
line.SetPosition (count+1, hit.point);
Debug.DrawLine(lazzerpoints[count],hit.point, Color.yellow,500);
direction=1;
}
else
{
if (Physics.Raycast (lazzerpoints[count],Vector3.left, out hit)&& hit.transform.tag != "mirror2"&& hit.transform.tag != "mirror1")
{
lazzerpoints[1]=(hit.point);
Debug.DrawLine(lazzerpoints[count],hit.point, Color.blue,500);
line.SetPosition (count+1, hit.point);
}
}
Debug.Log(hit.point +" hit.point"+count);
}
if(direction==3)
{
if (Physics.Raycast(lazzerpoints[count], Vector3.back, out hit,20)&& hit.transform.tag == "mirror1")
{
numlazzerpoints=numlazzerpoints+1;
System.Array.Resize(ref lazzerpoints,numlazzerpoints);
line.SetVertexCount (numlazzerpoints);
lazzerpoints[count+1]=(hit.point);
line.SetPosition (count+1, hit.point);
Debug.DrawLine(lazzerpoints[count],hit.point, Color.red,500);
direction=2;
}
else if (Physics.Raycast(lazzerpoints[count],Vector3.back,out hit)&& hit.transform.tag == "mirror2")
{
numlazzerpoints=numlazzerpoints+1;
System.Array.Resize(ref lazzerpoints,numlazzerpoints);
line.SetVertexCount (numlazzerpoints);
lazzerpoints[count+1]=(hit.point);
line.SetPosition (count+1, hit.point);
Debug.DrawLine(lazzerpoints[count],hit.point, Color.yellow,500);
direction=0;
}
else
{
if (Physics.Raycast (lazzerpoints[count],Vector3.back, out hit)&& hit.transform.tag != "mirror2"&& hit.transform.tag != "mirror1")
{
lazzerpoints[1]=(hit.point);
Debug.DrawLine(lazzerpoints[count],hit.point, Color.blue,500);
line.SetPosition (count+1, hit.point);
}
}
}
}
}
}
any help would be apreciated thanks!