引言
实现导弹跟随的游戏开发技巧
在游戏开发中,实现导弹跟随是一项常见而关键的技术。
下面我们将通过分析一段游戏代码,深入了解如何在游戏中实现导弹跟随的效果。
本文源工程在文末获取,小伙伴们自行前往。
直接上代码
import {
_decorator, CCFloat, Component, EventTouch, input, Input, instantiate, Node, Sprite, tween, UITransform, v3, Vec2, Vec3, view, Widget } from 'cc';
const {
ccclass, property } = _decorator;
@ccclass('BulletFollow2D')
export class BulletFollow2D extends Component {
@property(Node)
target: Node;
@property(Node)
bulletPfb: Node;
@property(Node)
bumpPfb: Node;
@property(CCFloat)
internal: number = 5;
@property(CCFloat)
speed: number = 100;
touchDown: boolean = false;
bullets: Node[] = [];
tick: number = this.internal;
start() {
input.on(Input.EventType.TOUCH_START, (event: EventTouch) => {
t