bullet.ts 536 B

123456789101112131415161718192021222324252627282930
  1. import { _decorator, Component, Node } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. const OUTOFRANGE = 50
  4. @ccclass('bullet')
  5. export class bullet extends Component {
  6. @property
  7. public bulletSpeed = 0;
  8. start() {
  9. }
  10. update(deltaTime: number) {
  11. const pos = this.node.position;
  12. const moveLength = pos.x + this.bulletSpeed;
  13. this.node.setPosition(moveLength, pos.y, pos.z)
  14. if(moveLength > OUTOFRANGE){
  15. this.node.destroy()
  16. }
  17. }
  18. }