(1)Random.valueを使う方法
using System.Collections; using System.Collections.Generic; using UnityEngine; public class RandomScale : MonoBehaviour { private void OnTriggerEnter(Collider other) { other.transform.localScale = new Vector3(1, 1, 1) * Random.value * 3; } }
(2)Random.Range()を使う方法
using System.Collections; using System.Collections.Generic; using UnityEngine; public class RandomScale : MonoBehaviour { private void OnTriggerEnter(Collider other) { other.transform.localScale = new Vector3(1, 1, 1) * Random.Range(1.2f, 5f); } }
(実行結果)
- 触れるたびにオブジェクトの大きさが変化すれば成功です。