Created
June 28, 2018 15:36
-
-
Save philipshen/140234c10d296725825d42fd32797d32 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {ccclass, property} = cc._decorator; | |
import Game from './Game' | |
@ccclass | |
export default class Meteor extends cc.Component { | |
game: Game | |
timeToLive = 10000 | |
timeAlive = 0 | |
onLoad() { | |
this.game = cc.find("/Game").getComponent("Game") | |
} | |
update(dt) { | |
if (!cc.isValid(this.node)) return | |
this.timeAlive += dt * 1000 | |
if (this.timeAlive >= this.timeToLive) { | |
this.node.destroy() | |
} | |
} | |
// Collider callbacks | |
onBeginContact(contact, selfCollider, otherCollider) { | |
if (otherCollider.node.name === "bullet") { | |
selfCollider.node.destroy() | |
otherCollider.node.destroy() | |
this.game.createExplosion(selfCollider.node.position) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment