Unity draw.ray 不起作用,尽管代码似乎正在运行

问题描述 投票:0回答:1

当脚本运行时,Debug.Log("Raydrawd")行起作用,但没有绘制光线。我已经尝试过改变颜色、距离以及物体和光线的位置。它没有显示。有什么想法吗?

using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AttackCheck : MonoBehaviour
{
    public bool hitting = false;
    Rigidbody2D rb;

    void Start()
    {
        hitting = false;
        rb = GetComponent<Rigidbody2D>();
    }

    void FixedUpdate()
    {
        RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.forward, 1000f);
        Debug.Log("Ray drawn");
        Debug.DrawRay(transform.position, transform.forward, Color.blue, 50f);
    }
}
c# unity-game-engine raycasting
1个回答
0
投票

尝试替换这行代码:

Debug.DrawRay(transform.position, transform.forward, Color.blue, 50f);

与:

Debug.DrawRay(transform.position, transform.forward, Color.blue);

您设置的时间没有任何意义,因为您是在运行时绘制射线,因此不需要使其保持活动状态超过一帧。

如果它仍然不起作用,请尝试在播放模式下启用小工具,按屏幕右上角的小工具按钮,您应该能够看到它。

© www.soinside.com 2019 - 2024. All rights reserved.