首页 > 解决方案 > 通过眼迹了解实体的类型

问题描述

GetEyeTrace 如何知道我面前的实体。我想检查一下,如果 entity == Weapon 然后做任何事情......

不管像下面这样:

if ply:GetEyeTrace().Entity.IsWeapon() then
        print("+")
    end

但是 IsWeapon() 函数没有。

标签: garrys-mod

解决方案


应该是 :IsWeapon()

您还应该真正检查实体是否有效。

local ent = ply:GetEyeTrace().Entity
if(!IsValid(ent)) then return end 
if(ent:IsWeapon()) then
    print("This is a weapon.")
end

推荐阅读