super-hero/assets/cc-game/scripts/game_play/hero/HeroMove.ts

22 lines
795 B
TypeScript

import { Vec3 } from 'cc';
import { _decorator, Component, Node } from 'cc';
import { UmUtil } from '../../../../cc-common/cc-util/UmUtil';
import { GameGlobalData } from '../../global/GameGlobalData';
import { JoyStick } from '../../../Test/JoyStick';
const { ccclass, property } = _decorator;
@ccclass('HeroMove')
export class HeroMove extends Component {
isTouchEnable = false;
moveSpeed: number = 5;
update(deltaTime: number) {
if (!JoyStick.IS_TOUCH_ENABLE || JoyStick.DIRECTION === Vec3.ZERO || !GameGlobalData.Instance.isStatePlay()) return;
this.moveSpeed = GameGlobalData.Instance.HERO_CONTROL_CONFIG.heroMoveSpeed;
this.node.position = UmUtil.plusTwoVector3(this.node.position, UmUtil.scaleVector3(JoyStick.DIRECTION, this.moveSpeed));
}
}