Cocos Creator 3D开发入门----CocosCreator3D篮球.zip
import { _decorator, Component, Node, RigidBodyComponent, PhysicMaterial, ColliderComponent } from "cc";
const { ccclass, property } = _decorator;
@ccclass("PhyMat")
export class PhyMat extends Component {
    
    @property
    private friction: number = 0; // 摩擦力
    @property
    private restitution: number = 0; // 弹力
    
    /* class member could be defined like this */
    // dummy = '';
    /* use `property` decorator if your want the member to be serializable */
    // @property
    // serializableDummy = 0;
    onLoad(): void{
        let comps: Array = this.node.getComponents(ColliderComponent) as Array;
        let mat = new PhysicMaterial();
        mat.friction = this.friction;
        mat.restitution = this.restitution;
        for(let i = 0; i < comps.length; i++){
            comps[i].material = mat;
        }
    }
    start () {
        // Your initialization goes here.
        
    }
    // update (deltaTime: number) {
    //     // Your update function goes here.
    // }
}
                                    
                                    
                                        
                                            1