using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LaserScript : MonoBehaviour {
LineRenderer laser;
int count;
//Vector3[] laserPoints = new Vector3[10];
void Start ()
{
laser = GetComponent<LineRenderer> ();
laser.enabled = false;
//laserPoints [2] = new Vector3 (10,0,5);
}
void Update () {
if (Input.GetKeyDown (KeyCode.LeftControl))
{
StopCoroutine ("Firing");
StartCoroutine ("Firing");
//Debug.DrawRay (transform.position, transform.forward, Color.red);
}
}
IEnumerator Firing()
{
laser.enabled = true;
while (Input.GetKey(KeyCode.LeftControl))
{
Ray ray = new Ray (transform.position, transform.forward);
RaycastHit hit;
laser.positionCount = 10;
laser.SetPosition (0, ray.origin);
if (Physics.Raycast (ray, out hit, 100))
{
laser.SetPosition (1, hit.point);
Debug.Log (hit.point);
if (hit.collider.tag == "Mirror")
{
laser.SetPosition (2, hit.point + 100.0f * Vector3.Reflect (transform.forward, hit.normal));
}
}
else
laser.SetPosition (1, ray.GetPoint (100));
if (Input.GetKeyDown (KeyCode.Space))
break;
}
yield return null;
laser.enabled = false;
}
}