Advertisement
Guest User

Untitled

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