import { _decorator, Animation, AudioClip, Collider2D, Component, Contact2DType, Node, RigidBody2D } from 'cc'; import AudioManager from '../Manager/AudioManager'; import { CameraController } from './CameraController'; 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(); AudioManager.playSfx(this._soundFx); if (velocity >= 40) { CameraController.instance.shake(0.08); } } }