Hi guys, I need help with C# Scripting using Raycast.

Hi guys, right now I’m trying to learn how to use Raycast in Unity. What I want to do is for an object to fire a beam and when the beam hits another object, it changes color, can you guys help me with that?

Linecast


using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Transform target;
    void Update()
    {
        if (Physics.Linecast(transform.position, target.position))
        {
            //change the color of your beam
        }
    }
}

Also you’ll need to render the line with LineRenderer