import FObject from "../object/FObject";

/**
 * 会变半透明的草地
 */
const {ccclass, property} = cc._decorator;

@ccclass
export default class FGrassShard extends cc.Component {
    public count:number = 0;
    onBeginContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, otherCollider: cc.PhysicsCollider){
        if(otherCollider.node.group == 'A'){
            let sobject = otherCollider.node.getComponent(FObject);
            if(sobject){
                this.count ++;
                this.node.opacity = 100;
            }
        }
    }
    onEndContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, otherCollider: cc.PhysicsCollider){
        if(otherCollider.node.group == 'A'){
            let sobject = otherCollider.node.getComponent(FObject);
            if(sobject){
                this.count --
                if(this.count <= 0){
                    this.node.opacity = 255;
                }
            }
        }
    }
}
