Raycast positioning problem

Hi, I’m trying to debug.log :“Position available” when the player looks at an object that is 5 or less units away. I’m having an issue with my raycast’s origin and direction though: they don’t start anywhere near my player gameobject (at least not by the looks of my debug.drawray) and “position available” is never output by the console. Here is my code:

using UnityEngine;
using System.Collections;

public class Phase1 : MonoBehaviour
{

    private float DistanceToPosition = 5;
    public void Positioning ()
    {
        RaycastHit hit;
        Ray PositioningRay = new Ray(transform.position, transform.forward);
        if (Input.GetButtonDown("Fire1"))
            {
                Debug.DrawRay(gameObject.transform.position, gameObject.transform.forward * DistanceToPosition);
                if (Physics.Raycast(PositioningRay, out hit, DistanceToPosition))
                {

                    if (hit.distance < DistanceToPosition)
                    {
                        Debug.Log("PositionAvailable");
                    }
                
                }
            }
	}
}

By the way the function is called from another script. I’d greatly appreciate any help.

Hmmm. The code itself look fine… (I’m assuming the script is attached to the player)

Where is the ray starting relative to your character?

Also you don’t need gameObject.transform.position, just transform.position is fine