上一篇文章写了一个简易版的蚂蚁庄园登山赛,有小伙伴留言说想要看星星球的,那么就写起来吧!
效果预览
配置环境 cocos creator 3d 1.0.0
小球点击
3d里节点无法用 cc.Node.EventType.TOUCH_START 监听。最终在论坛上找到一个 raycast 解决方法。参考代码如下。
start() {
systemEvent.on(SystemEventType.TOUCH_START, this.onClickBall, this);
}
private _ray = new geometry.ray();
private onClickBall(touch: Touch, event: EventTouch) {
const pos = touch.getLocation();
this.camera.screenPointToRay(pos.x, pos.y, this._ray);
const result: { node: Node }[] = this.node_ball_click.scene.renderScene['raycast'](this._ray);
if (result.some((i) => {
if (i.node === this.node_ball_cli