Search Unity

How do I cast an object on a raycast?

Discussion in 'Scripting' started by MP412rex, Jun 19, 2019.

  1. MP412rex

    MP412rex

    Joined:
    Jun 12, 2019
    Posts:
    3
    New to coding, need to make a raycast but have a small object follow the location where the ray is being casted.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class Raycast : MonoBehaviour
    {
    public GameObject OperatorDot;
    public Camera ControllerCam;

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
    Physics.Raycast(ControllerCam.transform.position, ControllerCam.transform.forward, out hit, range)
    {
    OperatorDot follow
    }
    }
    }

    Im stuck here, what to do?
     
  2. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Use code tags.

    Set the transform.position of the object you want to follow the cast to hit.point .