import { _decorator, Component, Node } from 'cc'; const { ccclass, property } = _decorator; @ccclass('ClickActiveNode') export class ClickActiveNode extends Component { @property(Node) targetNode: Node = null; @property active: boolean = true; protected onEnable(): void { this.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this); } protected onDisable(): void { this.node.off(Node.EventType.TOUCH_START, this.onTouchStart, this); } private onTouchStart(): void { if (this.targetNode) { if (this.active) { this.targetNode.active = this.active; } else this.targetNode.active = !this.targetNode.active; } } }