GameProp1000.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. const { ccclass, property } = cc._decorator;
  11. @ccclass
  12. export default class GameProp1000 extends cc.Component {
  13. // onLoad () {}
  14. //触发几次获得奖励
  15. triggerCount = 3
  16. //完事之后自己是否消失
  17. IsDeleteMe = true
  18. protected onEnable(): void {
  19. this.node.active = RewardMnr.getInstance().isEnable(this.getName())
  20. }
  21. onCollisionEnter(other: cc.CircleCollider, self: cc.BoxCollider) {
  22. if (this.triggerCount <= 0) {
  23. console.error('失效了');
  24. this.getComponent(cc.BoxCollider).enabled = false
  25. return
  26. }
  27. //如果碰撞了玩家
  28. if (other.node.getComponent(Character)) {
  29. this.triggerCount--
  30. if (this.triggerCount <= 0 && this.IsDeleteMe) {
  31. this.Reaward()
  32. }
  33. }
  34. }
  35. getName(): string {
  36. return this.node.parent.name + this.name + this.node.getPosition().x + this.node.getPosition().y
  37. }
  38. //奖励的方法
  39. Reaward() {
  40. RewardMnr.getInstance().addParabola(this.getName(), 3)
  41. this.node.destroy()
  42. }
  43. }