Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class TreeSeed : MonoBehaviour
  5. {
  6. public Color inheritedColor;
  7. public Color myColor;
  8. public float colorDelta;
  9. bool isGrowing = false;
  10. public float spawnTimeLow;
  11. public float spawnTimeHigh;
  12. //public float SplitTiming;
  13. public float DestroyMinRange;
  14. public float DestroyMaxRange;
  15. public float waitTime;
  16. public float maxSize;
  17. public float growFactor;
  18. //float lifeTime;
  19. //float t = 0f;
  20. public AnimationCurve curve;
  21. public int splitNum = 0;
  22. public int splitMax; //maximum number of splits that can ever happen
  23. public GameObject prefab;
  24. //MeshRenderer mr;
  25. // Use this for initialization
  26. //void OnEnable() {
  27. //lifeTime = Random.Range (DestroyMinRange, DestroyMaxRange);
  28. //t = .5f;
  29. //}
  30.  
  31.  
  32.  
  33. void OnEnable()
  34. {
  35. myColor = new Color(inheritedColor.r + Random.Range(-colorDelta, colorDelta), inheritedColor.g + Random.Range(-colorDelta, colorDelta), inheritedColor.b + Random.Range(-colorDelta, colorDelta), inheritedColor.a);
  36. GetComponent<MeshRenderer>().material.color = myColor;
  37. StartCoroutine("SeedOut");
  38. StartCoroutine("Scale");
  39. transform.localScale = Vector3.one;
  40. Destroy(gameObject, Random.Range(DestroyMinRange, DestroyMaxRange));
  41. }
  42. // Update is called once per frame
  43. void FixedUpdate()
  44. {
  45.  
  46. }
  47. public IEnumerator SeedOut()
  48. {
  49. while (splitNum < splitMax)
  50. {
  51. transform.localScale += new Vector3(0.1F, 0.1F, 0.1F);
  52. yield return new WaitForSeconds(Random.Range(spawnTimeLow, spawnTimeHigh));
  53. float x = curve.Evaluate(Time.timeSinceLevelLoad);
  54. float y = curve.Evaluate(Time.timeSinceLevelLoad);
  55. float z = curve.Evaluate(Time.timeSinceLevelLoad);
  56.  
  57.  
  58. GameObject obj = (GameObject)Instantiate(prefab, transform.position, Quaternion.identity);
  59. GameObject obj2 = (GameObject)Instantiate(prefab, transform.position, Quaternion.identity);
  60.  
  61.  
  62. splitNum++;
  63. GetComponent<TreeSeed>().inheritedColor = myColor;
  64. obj.GetComponent<TreeSeed>().splitNum = splitNum;
  65. } }
  66. public IEnumerator Scale()
  67. {
  68. float timer = 0;
  69.  
  70. while (true) // this could also be a condition indicating "alive or dead"
  71. {
  72. // we scale all axis, so they will have the same value,
  73. // so we can work with a float instead of comparing vectors
  74. while (maxSize > transform.localScale.x)
  75. {
  76. timer += Time.deltaTime;
  77. transform.localScale += new Vector3(.1F, .5F, .1F) * Time.deltaTime * growFactor;
  78. yield return null;
  79. }
  80. // reset the timer
  81.  
  82. yield return new WaitForSeconds(waitTime);
  83.  
  84. timer = 0;
  85. while (1 < transform.localScale.x)
  86. {
  87. timer += Time.deltaTime;
  88. transform.localScale -= new Vector3(1, 1, 1) * Time.deltaTime * growFactor;
  89. yield return null;
  90. }
  91.  
  92. timer = 0;
  93. yield return new WaitForSeconds(waitTime);
  94. }
  95.  
  96.  
  97. //if (isGrowing)
  98. //transform.localScale = new Vector3 ((.1f) + transform.localScale.x, (.1f) + transform.localScale.y, (.1f) + transform.localScale.z);
  99. //else
  100. //transform.localScale = new Vector3 ((-.1f) + transform.localScale.x, (-.1f) + transform.localScale.y, (-.1f) + transform.localScale.z);
  101.  
  102.  
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement