0
using System.Collections;
using System.Collections.Generic;

using UnityEngine;

public class SharRay : MonoBehaviour
    
{
    private Transform player;
    
    void Start()
    {
        player = GameObject.FindGameObjectWithTag("Player").transform;
    }

    
    void LateUpdate()
    {
        Ray ray = Camera.main.ScreenPointToRay(player.position);
        Debug.DrawRay(transform.position, player.position, Color.yellow);

    }
}
0

1 ответ 1

0

transform.position это не ScreenPoint (точка на экране), а WorldPosition (позиция в сцене).

public class Foo : MonoBehaviour
{
    [SerializeField] private Transform _target;
    private Transform _camera;

    private void Start ()
    {
        _camera = Camera.main.transform;
    }

    private void Update ()
    {
        Ray ray = new Ray(_camera.position, _target.position - _camera.position);
        Debug.DrawRay(ray.origin, ray.direction, Color.cyan);
    }
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.