init
This commit is contained in:
59
assets/src/gameManager.ts
Normal file
59
assets/src/gameManager.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { _decorator, Component, Node, Prefab, instantiate } from 'cc';
|
||||
import { zd } from './zd';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('gameManager')
|
||||
export class gameManager extends Component {
|
||||
|
||||
@property(Node)
|
||||
public plant:Node = null;
|
||||
|
||||
@property(Node)
|
||||
public zdOut:Node = null;
|
||||
|
||||
@property(Prefab)
|
||||
public zd1:Prefab = null;
|
||||
|
||||
/**子弹移动速度*/
|
||||
@property
|
||||
public zd_speed:number = 0.2;
|
||||
|
||||
/**发射子弹的间隔*/
|
||||
@property
|
||||
public new_zd_time = 0.3;
|
||||
|
||||
/**当前发射子弹的间隔*/
|
||||
@property
|
||||
public _new_zd_time = 0;
|
||||
|
||||
private _isTouch:boolean = false;
|
||||
|
||||
start() {
|
||||
this._new_zd_time = this.new_zd_time;
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
this._new_zd_time += deltaTime;
|
||||
if(this._isTouch && this._new_zd_time > this.new_zd_time){
|
||||
this.createZd();
|
||||
this._new_zd_time = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public createZd(){
|
||||
const zd01 = instantiate(this.zd1);
|
||||
zd01.setParent(this.zdOut);
|
||||
const ppos = this.plant.position;
|
||||
zd01.setPosition(ppos.x, ppos.y, ppos.z - 1);
|
||||
const zdcop = zd01.getComponent(zd);
|
||||
console.log(this.zd_speed);
|
||||
zdcop.z_speed = this.zd_speed;
|
||||
}
|
||||
|
||||
isTouch(val:boolean){
|
||||
this._isTouch = val;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user