import { _decorator, Component, Input, input, instantiate, Node, Prefab } from 'cc'; const { ccclass, property } = _decorator; @ccclass('Test') export class Test extends Component { @property(Prefab) private someThing: Prefab; someNode: Node; protected start(): void { input.on(Input.EventType.MOUSE_DOWN, this.ActiveNode, this); input.on(Input.EventType.MOUSE_UP, this.DeActiveNode, this); } private ActiveNode(): void { if (this.someNode == null) { this.someNode = instantiate(this.someThing); this.someNode.parent = this.node; this.someNode.setPosition(0, 0, 0); } else this.someNode.active = true; } private DeActiveNode(): void { this.someNode.active = false; } }