今回は、オブジェクトを巨大風船のように膨らませる方法について紹介します。
敵の巨大化など、利用できる場面は意外と多いと思うので活用してもらえればと思います。
オブジェクトを巨大風船のように膨らませる方法【Unity】
敵の動きに関するスクリプト「EnemyMove」を作成します。
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
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class EnemyMove : MonoBehaviour | |
{ | |
Vector3 Scale; | |
// Start is called before the first frame update | |
void Start() | |
{ | |
Scale = transform.localScale; | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
transform.localScale = new Vector3(Scale.x+Time.deltaTime,Scale.y+Time.deltaTime, Scale.z+Time.deltaTime); | |
Scale = transform.localScale; | |
} | |
} |
スクリプトは至ってシンプルですね。
Updateメソッド内でTime.deltaTimeを使って、Scaleの数値を増やしていきます。
たったこれだけでオブジェクトを膨らませ続けることが可能です。後はこのスクリプトを膨らませたいオブジェクトにアタッチするだけです。
動画プレーヤー
00:00
00:00
ゲームを実行するとこんな感じです。
特に条件は付けていないので、実行している限り無限に大きくなり続けますね。
本当の風船のように割れるようにするのであれば、指定したサイズを超えた時点でDestroyを使ってオブジェクトを削除し、そのタイミングでエフェクトを表示すると良いと思います。