为什么我的子弹不能移动?
来自课程:CocosCreator3.8入门教程-微信飞机大战
跟老师写的一样,但子弹生成后不会移动
import { _decorator, Component, EventTouch, instantiate, Node, Prefab, Vec2, Vec3 } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('Player')
export class Player extends Component {
boundaryX: number = 230
boundaryY: number = 380
shootTime:number = 0
@property
shootRate:number = 0.5
@property(Node)
bullet1Parent: Node = null
@property(Prefab)
bullet1Prefab: Prefab = null
@property(Node)
bullet1Position: Node = null
protected onLoad(): void {
this.node.on(Node.EventType.TOUCH_MOVE, this.onTouchMove, this)
}
protected onDestroy(): void {
this.node.off(Node.EventType.TOUCH_MOVE, this.onTouchMove, this)
}
onTouchMove(event: EventTouch) {
let targetPosistion = new Vec3(this.node.position.x + event.getDeltaX(), this.node.position.y + event.getDeltaY())
if (targetPosistion.x < -this.boundaryX) {
targetPosistion.x = -this.boundaryX
} else if (targetPosistion.x > this.boundaryX) {
targetPosistion.x = this.boundaryX
}
if (targetPosistion.y < -this.boundaryY) {
targetPosistion.y = -this.boundaryY
} else if (targetPosistion.y > this.boundaryY) {
targetPosistion.y = this.boundaryY
}
this.node.setPosition(targetPosistion)
}
start() {
}
update(deltaTime: number) {
this.shootTime += deltaTime
if (this.shootTime >= this.shootRate) {
this.shootTime = 0
const bullet1 = instantiate(this.bullet1Prefab)
this.bullet1Parent.addChild(bullet1)
bullet1.setWorldPosition(this.bullet1Position.worldPosition)
}
}
}


