1234567891011121314151617181920212223242526272829 |
- using UnityEngine;
- using System.Collections;
- public class F3DRandomize : MonoBehaviour {
- private new Transform transform; // Cached transform
- private Vector3 defaultScale; // Default scale
- public bool RandomScale, RandomRotation; // Randomize flags
- public float MinScale, MaxScale; // Min/Max scale range
- public float MinRotation, MaxRotaion; // Min/Max rotation range
- void Awake()
- {
- // Store transform component and default scale
- transform = GetComponent<Transform>();
- defaultScale = transform.localScale;
- }
- // Randomize scale and rotation according to the values set in the inspector
- void OnEnable()
- {
- if (RandomScale)
- transform.localScale = defaultScale * Random.Range(MinScale, MaxScale);
- if(RandomRotation)
- transform.rotation *= Quaternion.Euler(0, 0, Random.Range(MinRotation, MaxRotaion));
- }
- }
|