猫史档案馆


[代码求助]谁能帮我看看这段代码出了什么问题?

用户:苏联的达瓦里希球苏联的达瓦里希球查看:2 回复:3 评论:2 创建时间:2023-06-06T22:14:48


就是这段:center_image

问题你们也看到了,我在类声明中把shoot定义为属性,并把一个匿名函数(确认可以使用)赋值给他(11~32行),可他告诉我喵.shoot不是一个函数,有哪位大佬可以帮我看一下,问题在哪里,能不能帮我改一下?

附代码(喵支类全部代码)

class 喵 {
    //喵支类,在喵战时可用
    constructor(entity = new Box3Entity()) {
        this.bullet = 10
        this.player = entity.player.userKey
        this.name = entity.player.name
        this.mesh = 'mesh/98k喵.vb'
        this.shoot = function(raycast=new Box3RaycastResult()){
            var bullet = world.createEntity({
                mesh:'mesh/喵子弹.vb',
                position:[entity.position],
                meshScale:[0.0625,0.0625,0.0625],
                meshOrientation:entity.meshOrientation,
                velocity:raycast.hitPosition,
                meshMetalness:255,
                meshEmissive:255,
                fixed:false
            })
            bullet.name = this.name,
            bullet.player = this.player,
            bullet.onEntityContact(({ other })=>{
                if(other.isPlayer){
                    if(other.player.userKey != bullet.player){
                        other.hurt(1000,{ damageType:'喵伤',attacker:entity })
                        bullet.destroy()//销毁子弹
                    }
                }
            })
        }
    }
}


回复

上一页1 页 / 共 1下一页
苏联的达瓦里希球苏联的达瓦里希球

枪 支和手 枪都是屏蔽词……

点赞0


评论


苏联的达瓦里希球苏联的达瓦里希球

刚找到问题了:center_image

第267行的玩家属性entity.player.gun写成了gun类

点赞0


评论


145a145a

gun是个类,你定义的shoot是他的实例化方法,而你当成静态方法用了。

点赞0


评论