canvas: Node = null;
StartPos: Vec3 = new Vec3();
onLoad() {
this.canvas = find("Canvas");
this.StartPos = this.node.position;
this.node.on(Node.EventType.TOUCH_START, this.Tool_Start, this);
this.node.on(Node.EventType.TOUCH_MOVE, this.Tool_Move, this);
this.node.on(Node.EventType.TOUCH_END, this.Tool_End, this);
this.node.on(Node.EventType.TOUCH_CANCEL, this.Tool_End, this);
}
start() {
// [3]
}
update(deltaTime: number) {
// [4]
//log(this.StartPos)
}
Tool_Start(event: EventTouch) {
Tween.stopAllByTarget(this.node);
this.node.getComponent(Animation).stop();
tween(this.node).to(0.2, { scale: v3(1, 1) }).start();
let posV2: Vec2 = event.getUILocation();
let posV3 = this.canvas.getComponent(UITransform).convertToNodeSpaceAR(v3(posV2.x, posV2.y));
this.node.active = true;
this.node.setPosition(posV3);
}
Tool_Move(event: EventTouch) {
let posV2: Vec2 = event.getUILocation();
let posV3 = this.canvas.getComponent(UITransform).convertToNodeSpaceAR(v3(posV2.x, posV2.y));
this.node.setPosition(posV3);
}
Tool_End(event: EventTouch) {
Tween.stopAllByTarget(this.node);
log(this.StartPos)
tween(this.node).to(0.5, { position: this.StartPos, scale: v3(0.8, 0.8) }).call(() => {
this.node.getComponent(Animation).play();
}).start();
}
这个StartPos在拖动时一直在变,还有拖完一次后就不能再拖了,这个脚本是挂在拖拽物体本身上的,求大佬解救

