F3DRandomize.cs 967 B

1234567891011121314151617181920212223242526272829
  1. using UnityEngine;
  2. using System.Collections;
  3. public class F3DRandomize : MonoBehaviour {
  4. private new Transform transform; // Cached transform
  5. private Vector3 defaultScale; // Default scale
  6. public bool RandomScale, RandomRotation; // Randomize flags
  7. public float MinScale, MaxScale; // Min/Max scale range
  8. public float MinRotation, MaxRotaion; // Min/Max rotation range
  9. void Awake()
  10. {
  11. // Store transform component and default scale
  12. transform = GetComponent<Transform>();
  13. defaultScale = transform.localScale;
  14. }
  15. // Randomize scale and rotation according to the values set in the inspector
  16. void OnEnable()
  17. {
  18. if (RandomScale)
  19. transform.localScale = defaultScale * Random.Range(MinScale, MaxScale);
  20. if(RandomRotation)
  21. transform.rotation *= Quaternion.Euler(0, 0, Random.Range(MinRotation, MaxRotaion));
  22. }
  23. }