| | | 1 | | using System.Collections; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using UnityEngine; |
| | | 4 | | |
| | | 5 | | [RequireComponent(typeof(LineRenderer))] |
| | | 6 | | public class LaserBeamSender : MonoBehaviour |
| | | 7 | | { |
| | 32 | 8 | | private bool isConnected = true; |
| | 32 | 9 | | private float maxLaserLenght = 20f; |
| | | 10 | | LineRenderer laserBeam; |
| | | 11 | | [SerializeField] private room3 roomData; |
| | | 12 | | |
| | | 13 | | private void Awake() |
| | 24 | 14 | | { |
| | 24 | 15 | | laserBeam = GetComponent<LineRenderer>(); |
| | 24 | 16 | | } |
| | | 17 | | |
| | | 18 | | // Update is called once per frame |
| | | 19 | | void Update() |
| | 10064 | 20 | | { |
| | | 21 | | RaycastHit hit; |
| | | 22 | | |
| | 10064 | 23 | | if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.right), out hit, maxLaserLenght)) |
| | 10064 | 24 | | { |
| | 10064 | 25 | | if (hit.collider.gameObject.CompareTag("Receiver") && !isConnected) |
| | 28 | 26 | | { |
| | 28 | 27 | | isConnected = true; |
| | 28 | 28 | | roomData.DesactivateLaser(); |
| | 10064 | 29 | | } else if (!hit.collider.gameObject.CompareTag("Receiver") && isConnected) |
| | 30 | 30 | | { |
| | 30 | 31 | | isConnected = false; |
| | 30 | 32 | | roomData.SetLaser(); |
| | 30 | 33 | | } |
| | 10064 | 34 | | Vector3 laserBeamEnd = hit.point; |
| | 10064 | 35 | | laserBeam.SetPosition(0, transform.position); |
| | 10064 | 36 | | laserBeam.SetPosition(1, laserBeamEnd); |
| | 10064 | 37 | | } |
| | 10064 | 38 | | } |
| | | 39 | | } |