import { _decorator, Collider2D, Component, Contact2DType, Node, Animation, RigidBody2D, AudioClip } from 'cc'; import { CameraController } from './CameraController'; import { SoundManager } from '../Manager/SoundManager'; 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; @property({ type: AudioClip, visible: true }) private _soundFx: AudioClip; protected onLoad(): void { this._collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this); } onBeginContact(self: Collider2D, other: Collider2D) { this._animation.play(); const velocity = other.getComponent(RigidBody2D).linearVelocity.length(); SoundManager.instance.playSfx(this._soundFx); if (velocity >= 40) { CameraController.instance.shake(0.08); } } }