Skip to content

Instantly share code, notes, and snippets.

@philipshen
Created June 28, 2018 15:36
Show Gist options
  • Save philipshen/140234c10d296725825d42fd32797d32 to your computer and use it in GitHub Desktop.
Save philipshen/140234c10d296725825d42fd32797d32 to your computer and use it in GitHub Desktop.
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