Skip to content

Instantly share code, notes, and snippets.

@flushpot1125
Last active June 28, 2020 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flushpot1125/77602620792955c52f33ccef125f2d14 to your computer and use it in GitHub Desktop.
Save flushpot1125/77602620792955c52f33ccef125f2d14 to your computer and use it in GitHub Desktop.
food.actionManager.registerAction(
new ExecuteCodeAction(
{
trigger: ActionManager.OnIntersectionEnterTrigger,//アクション発生のきっかけ。ここではparameterで指定されたものと衝突したら。
parameter: snake,
},
//以下のfunctionは、foodとsnakeが衝突したら実行される
function () {
//パーティクルを発生させる
function () {
var particleSystem = addParticlesToMesh(food, scene);
scene.removeMesh(food);
sleep(250).then(() => {
removeParticlesFromMesh(particleSystem);
let currentScore = incrementScore();
//add new mesh length to snake
let currentSpeed = snakeSpeed;
//snakeが長くなる
snake.scaling.addInPlace(new Vector3(1, 0, 0));
//increase speed
snakeSpeed = currentSpeed * 2;
//新しいフルーツを生成する (UnityでいうInstantiate)
addNom(scene, snake, snakeSpeed);
});
}
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment