You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.2 KiB
51 lines
1.2 KiB
import { _decorator, Component, Node, Tween, tween, v3, Vec3} from 'cc';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
@ccclass('TreasureSkill')
|
|
export class TreasureSkill extends Component {
|
|
|
|
protected onLoad(): void {
|
|
|
|
}
|
|
|
|
protected onEnable(): void {
|
|
// this.scheduleOnce(()=>{
|
|
// this.startAtk()
|
|
// },0.1)
|
|
}
|
|
/**开始扔武器 */
|
|
startAtk() {
|
|
let targetPos = v3(50,this.node.y,0)
|
|
this.straightAtkTo(this.node,targetPos.clone(),v3(1,1,1),()=>{
|
|
this.removeBullet()
|
|
})
|
|
}
|
|
/**
|
|
* 直线攻击到打击点
|
|
* @param self
|
|
* @param enemy
|
|
* @param enemyTarget
|
|
* @param speed
|
|
* @param enemySpeed
|
|
* @param callback
|
|
*/
|
|
public straightAtkTo(self: Node, targetPos: Vec3, targetScale:Vec3,callback: Function) {
|
|
let dis = Vec3.distance(self.position,targetPos)
|
|
let speed = 800
|
|
let dt = dis/speed
|
|
Tween.stopAllByTarget(self);
|
|
tween(self)
|
|
.to(dt, { position: targetPos,scale:targetScale })
|
|
.call(()=>{
|
|
callback && callback()
|
|
})
|
|
.start();
|
|
}
|
|
/**移除子弹 */
|
|
removeBullet(){
|
|
gg.res.putNode(this.node)
|
|
}
|
|
}
|
|
|
|
|
|
|