Hello,
I am new to Unity and I am following the tutorials one by one.
Now I followed Lesson 8. Fun with lasers.
Problem is that when I press the left mouse button the laserbeam is not displayed.
Only The ´gun´ is displayed properly.
I think it it´s because I am using a newer version of unity than used in the tutorial, but I am not sure.
Maybe I messed up. Below you can find some screenshots and the script I used.
If someone can have a look at it that would be great
Laserscript
using UnityEngine;
using System.Collections;
public class LaserScript : MonoBehaviour
{
LineRenderer line;
void Start ()
{
line = gameObject.GetComponent<LineRenderer> ();
line.enabled = false;
}
void Update ()
{
if (Input.GetButtonDown ("Fire1"))
{
StopCoroutine("FireLaser");
StartCoroutine("FireLaser");
}
}
IEnumerable FireLaser ()
{
line.enabled = true;
while (Input.GetButton("Fire1"))
{
Ray ray = new Ray(transform.position, transform.forward);
line.SetPosition(0, ray.origin);
line.SetPosition(1, ray.GetPoint(100));
yield return null;
}
line.enabled = false;
}
}