(スクリプトの作成)
- 新規にC#スクリプトの作成
- 名前を「ScaleChangeX」に変更
- 下記のコードを書いてチェック
using UnityEngine;
public class ScaleChangeX : MonoBehaviour
{
private Vector3 initialScale;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
initialScale = transform.localScale;
}
// Update is called once per frame
void Update()
{
// ★「GetKeyDown」と「GetKey」の違いをおさえる(ポイント)
if (Input.GetKey(KeyCode.C))
{
// 「*=」の意味を考えよう
transform.localScale *= 1.005f;
}
}
}
(実行確認)
- スクリプトを好きなオブジェクトに追加
- ゲームを再生
- Cボタンを押し続けると、オブジェクトが徐々に大きくなれば成功です。
(復習)
- 「V」ボタンを押したら、「一瞬で」初期の大きさに戻るようにコードを追加してください。