Fun with Lasers, I can't get it to work.

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 :slight_smile:

alt text

alt text

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;
	}
}

It looks as if your line renderer does not have any materials applied. It needs something to render. Apply a material with a particles shader, for example. Or start with a simple diffuse color texture. Your line renderer will show whatever it renders already in the scene view, so you can design it the way you want it. Your script then enables and disables it and/or sets the start and end position/ray length.

PS: Found the mistake on line 25: The Coroutine has to return IEnumerator.