GameProp1000.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
  7. import Character from "../Character/Character";
  8. import EventName from "../EventName/EventName";
  9. import RewardMnr from "../Template/RewardMnr";
  10. import Prop from "./Prop";
  11. const { ccclass, property } = cc._decorator;
  12. @ccclass
  13. export default class GameProp1000 extends Prop {
  14. // onLoad () {}
  15. //触发几次获得奖励
  16. triggerCount = 1
  17. //完事之后自己是否消失
  18. IsDeleteMe = true
  19. protected onEnable(): void {
  20. this.node.active = RewardMnr.getInstance().isEnable(this.Flag())
  21. }
  22. onCollisionEnter(other: cc.CircleCollider, self: cc.BoxCollider) {
  23. if (this.triggerCount <= 0) {
  24. console.error('失效了');
  25. this.getComponent(cc.BoxCollider).enabled = false
  26. return
  27. }
  28. //如果碰撞了玩家
  29. if (other.node.getComponent(Character)) {
  30. this.triggerCount--
  31. if (this.triggerCount <= 0 && this.IsDeleteMe) {
  32. this.Reaward()
  33. }
  34. }
  35. }
  36. //奖励的方法
  37. Reaward() {
  38. RewardMnr.getInstance().addParabola(this.Flag(), 3)
  39. this.node.destroy()
  40. }
  41. }