项目结构如下图:
1.说明:为了测试方便我都把两个脚本挂载到了Canvas上了。加了三个精灵组件一个dayuan(大圆),就是大浅蓝色的,作为摇杆盘,一个xiaoyuan(小圆)就是深蓝色的作为摇杆,还有一个feidie(飞碟)作为被控制的角色。其中xiaoyuan精灵节点时dayuan的子节点。
2.把下面两个脚本组件都挂在到Canvas上
摇杆代码Joystick.ts
import { _decorator, Component, Node, Vec3, Touch, UITransform, v3 } from 'cc';
const { ccclass, property } = _decorator;
/**
* Predefined variables
* Name = JoyStick
* DateTime = Mon Jun 20 2022 14:42:05 GMT+0800 (中国标准时间)
* Author = fangfan001
* FileBasename = JoyStick.ts
* FileBasenameNoExtension = JoyStick
* URL = db://assets/scripts/JoyStick.ts
* ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
*
*/
@ccclass('JoyStick')
export class JoyStick extends