Having a problem about coding "RayCast" or "RayCastHit"

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.

It’s RaycastHit, not RayCastHit. The case here (uppercase ‘C’ vs lowercase ‘c’) is important.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms