Question by
Gafas1995JSVD · Feb 18, 2019 at 01:43 AM ·
c#scripting problemcollidercolorraycasting
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?
Comment
Answer by bpaynom · Feb 18, 2019 at 08:03 PM
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