Advertisement
Guest User

Untitled

a guest
Oct 7th, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. //Solarnrg's untested code
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using UnityEngine;
  8.  
  9. public class MuMechModuleDrill : PartModule
  10. {
  11. GameObject rock1, rock2, rock3;
  12. static double spawnTimer = 0;
  13.  
  14.  
  15. public void FixedUpdate()
  16. {
  17.  
  18. if (vessel == null)
  19. {
  20. return;
  21. }
  22.  
  23. if (!rock1)
  24. {
  25. rock1 = PartReader.Read(KSPUtil.ApplicationRootPath + "Parts/mumech_drill/rock1/", "model", ".mu");
  26. rock1.name = "rock1";
  27. rock1.transform.position = new Vector3(1e10f, 1e10f, 1e10f);
  28.  
  29. rock2 = PartReader.Read(KSPUtil.ApplicationRootPath + "Parts/mumech_drill/rock2/", "model", ".mu");
  30. rock2.name = "rock2";
  31. rock2.transform.position = new Vector3(1e10f, 1e10f, 1e10f);
  32. rock3 = PartReader.Read(KSPUtil.ApplicationRootPath + "Parts/mumech_drill/rock3/", "model", ".mu");
  33. rock3.name = "rock3";
  34. rock3.transform.position = new Vector3(1e10f, 1e10f, 1e10f);
  35. }
  36.  
  37. if (drillHitTerrain())
  38. {
  39.  
  40. spawnTimer += TimeWarp.fixedDeltaTime;
  41. if (spawnTimer >= 1)
  42. {
  43. print("Spawning rock!"); int whichrock = UnityEngine.Random.range(1,3);
  44.  
  45. switch whichrock
  46.  
  47. case 1:
  48.  
  49. GameObject newRock = (GameObject)GameObject.Instantiate(rock1);newRock.transform.position = part.transform.position + UnityEngine.Random.onUnitSphere;
  50. newRock.transform.rotation = UnityEngine.Random.rotation;
  51. newRock.AddComponent<Rigidbody>();
  52. newRock.rigidbody.AddForce(UnityEngine.Random.onUnitSphere * UnityEngine.Random.value * 10, ForceMode.Impulse);
  53. spawnTimer = 0;
  54.  
  55. case 2:
  56.  
  57. GameObject newRock = (GameObject)GameObject.Instantiate(rock2);newRock.transform.position = part.transform.position + UnityEngine.Random.onUnitSphere;
  58. newRock.transform.rotation = UnityEngine.Random.rotation;
  59. newRock.AddComponent<Rigidbody>();
  60. newRock.rigidbody.AddForce(UnityEngine.Random.onUnitSphere * UnityEngine.Random.value * 10, ForceMode.Impulse);
  61. spawnTimer = 0;
  62.  
  63. case 3:
  64.  
  65. GameObject newRock = (GameObject)GameObject.Instantiate(rock3);newRock.transform.position = part.transform.position + UnityEngine.Random.onUnitSphere;
  66. newRock.transform.rotation = UnityEngine.Random.rotation;
  67. newRock.AddComponent<Rigidbody>();
  68. newRock.rigidbody.AddForce(UnityEngine.Random.onUnitSphere * UnityEngine.Random.value * 10, ForceMode.Impulse);
  69. spawnTimer = 0;
  70. }
  71. }
  72. else
  73. {
  74. spawnTimer = 0;
  75. }
  76. base.OnFixedUpdate();
  77. }
  78.  
  79.  
  80. private bool drillHitTerrain()
  81. {
  82. Transform drill = base.transform.FindChild ("model").FindChild("Cylinder");
  83. if(Physics.Raycast (drill.position, Vector3.forward,0.85f,1 << 15))
  84. {
  85. drill.transform.Rotate(Vector3.up * (600f*TimeWarp.deltaTime));
  86. return true;
  87. }
  88. else
  89. {
  90. return false;
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement