Here is the code i tried:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TargetActivision : MonoBehaviour
{
public static float distanceFromTarget;
public float toTarget;
void Update()
{
RayCastHit hit;
if(Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit))
{
toTarget = hit.distance;
distanceFromTarget = toTarget;
}
}
}
I actually firstly tried “RayCast” instead of “RayCastHit” but its giving an error like:
The type or namespace name ‘RayCastHit’ could not be found (are you missing a using directive or an assembly reference?)
How can i fix that? Please help me, coding with c# is really hell because of errors.