Saw.ts 914 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import EventType from "./EventType";
  2. import Role from "./Role";
  3. const {ccclass, property} = cc._decorator;
  4. @ccclass
  5. export default class Saw extends cc.Component {
  6. canGet:boolean = true;
  7. onLoad(){
  8. this.node.group = EventType.GROUP_OBJECT;
  9. this.node.getChildByName('Prop').addComponent(Prop).init(this);
  10. }
  11. onCollisionStay(other:cc.Collider){
  12. if(this.canGet){
  13. let role = other.node.getComponent(Role);
  14. if(role&&role.pickUpSaw()){
  15. this.canGet = false;
  16. window.controller.destroySaw(this.node);
  17. }
  18. }
  19. }
  20. }
  21. class Prop extends cc.Component {
  22. parentScript:any;
  23. init(parentScript:any){
  24. this.parentScript = parentScript;
  25. this.node.group = EventType.GROUP_PROP;
  26. }
  27. onCollisionStay(other:cc.Collider){
  28. this.parentScript.onCollisionStay(other);
  29. }
  30. }