24 lines
667 B
C#
24 lines
667 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class Laser : MonoBehaviour
|
|
{
|
|
float maxDistance = 500.0f;
|
|
|
|
LineRenderer laserLine;
|
|
|
|
void Start()
|
|
{
|
|
laserLine = GetComponent<LineRenderer> ();
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.right);
|
|
float endpointX = maxDistance;
|
|
if (hit.collider) endpointX = hit.collider.transform.position.x;
|
|
laserLine.SetPosition (0, new Vector3(transform.position.x, transform.position.y, 0));
|
|
laserLine.SetPosition (1, new Vector3(endpointX, transform.position.y, 0));
|
|
}
|
|
}
|