1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- // Learn TypeScript:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
- // Learn Attribute:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
- import Character from "../Character/Character";
- import EventName from "../EventName/EventName";
- import RewardMnr from "../Template/RewardMnr";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class GameProp1000 extends cc.Component {
- // onLoad () {}
- //触发几次获得奖励
- triggerCount = 3
- //完事之后自己是否消失
- IsDeleteMe = true
- protected onEnable(): void {
- this.node.active = RewardMnr.getInstance().isEnable(this.getName())
- }
- onCollisionEnter(other: cc.CircleCollider, self: cc.BoxCollider) {
- if (this.triggerCount <= 0) {
- console.error('失效了');
- this.getComponent(cc.BoxCollider).enabled = false
- return
- }
- //如果碰撞了玩家
- if (other.node.getComponent(Character)) {
- this.triggerCount--
- if (this.triggerCount <= 0 && this.IsDeleteMe) {
- this.Reaward()
- }
- }
- }
- getName(): string {
- return this.node.parent.name + this.name + this.node.getPosition().x + this.node.getPosition().y
- }
- //奖励的方法
- Reaward() {
- RewardMnr.getInstance().addParabola(this.getName(), 3)
- this.node.destroy()
- }
- }
|