24.5 C
Brasília
quinta-feira, maio 8, 2025

Obtenha componente quando o Collider Set off – Cocos Creator


Eu quero obter o planeta componente quando o jogador entrar em contato, mas não é funcionar

ContactPlanet(){
    if(this.collider){
        this.collider.on(Contact2DType.BEGIN_CONTACT,this.onBeginContactPlanet, this);
        this.collider.on(Contact2DType.END_CONTACT,this.onEndContactPlanet, this);
    }
}
onBeginContactPlanet(contact: any, selfCollider: CircleCollider2D, otherCollider: CircleCollider2D){
    console.log("Đã va chạm");
    this.isPlanet = true;
    this.GetComponentPlanet(otherCollider);
}
onEndContactPlanet(contact: any, selfCollider: CircleCollider2D, otherCollider: CircleCollider2D){
    console.log("Thoát va chạm");
    this.isPlanet = false;
}
// @property({kind:CircleCollider2D})
// planetCollider: CircleCollider2D; <------- variable declaration
GetComponentPlanet(planetCollider: CircleCollider2D) {
    console.log(planetCollider);
    if (planetCollider instanceof CircleCollider2D) {
        this.planetCollider = planetCollider;
        this.acreage = this.planetCollider.radius;
        console.log
    }
}

Você não passou pelo componente de outro colisor, você acabou de definir o tipo do outro colisor
use othercollider = this.getComponent (cc.circlecoolder2d);
acima disso.getComponentPlanet (OtherCollider);
e então tente

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Stay Connected

0FansLike
0FollowersFollow
0SubscribersSubscribe
- Advertisement -spot_img

Latest Articles