FGrassShard.ts 988 B

12345678910111213141516171819202122232425262728293031
  1. import FObject from "../object/FObject";
  2. /**
  3. * 会变半透明的草地
  4. */
  5. const {ccclass, property} = cc._decorator;
  6. @ccclass
  7. export default class FGrassShard extends cc.Component {
  8. public count:number = 0;
  9. onBeginContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, otherCollider: cc.PhysicsCollider){
  10. if(otherCollider.node.group == 'A'){
  11. let sobject = otherCollider.node.getComponent(FObject);
  12. if(sobject){
  13. this.count ++;
  14. this.node.opacity = 100;
  15. }
  16. }
  17. }
  18. onEndContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, otherCollider: cc.PhysicsCollider){
  19. if(otherCollider.node.group == 'A'){
  20. let sobject = otherCollider.node.getComponent(FObject);
  21. if(sobject){
  22. this.count --
  23. if(this.count <= 0){
  24. this.node.opacity = 255;
  25. }
  26. }
  27. }
  28. }
  29. }