19 lines
595 B
TypeScript
19 lines
595 B
TypeScript
import { _decorator, Collider2D, Component, Contact2DType, Node, Animation } from 'cc';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('SlingShot')
|
|
export default class SlingShot extends Component {
|
|
@property({ type: Animation, visible: true })
|
|
private _animation: Animation;
|
|
@property({ type: Collider2D, visible: true })
|
|
private _collider: Collider2D;
|
|
|
|
protected onLoad(): void {
|
|
this._collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
|
|
}
|
|
|
|
onBeginContact(self: Collider2D, other: Collider2D) {
|
|
this._animation.play();
|
|
}
|
|
}
|