r4m0n

Drill baby Drill!

Aug 29th, 2012
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.62 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.     double spawnTimer = 0;
  11.  
  12.     public void FixedUpdate()
  13.     {
  14.         if (vessel == null)
  15.         {
  16.             return;
  17.         }
  18.  
  19.         if (!rock1)
  20.         {
  21.             rock1 = PartReader.Read(KSPUtil.ApplicationRootPath + "Parts/mumech_drill/rock1/", "model", ".mu");
  22.             rock1.name = "rock1";
  23.             rock1.transform.position = new Vector3(1e10f, 1e10f, 1e10f);
  24.  
  25.             rock2 = PartReader.Read(KSPUtil.ApplicationRootPath + "Parts/mumech_drill/rock2/", "model", ".mu");
  26.             rock2.name = "rock2";
  27.             rock2.transform.position = new Vector3(1e10f, 1e10f, 1e10f);
  28.         }
  29.  
  30.         if (part.Landed)
  31.         {
  32.             spawnTimer += TimeWarp.fixedDeltaTime;
  33.             if (spawnTimer >= 5)
  34.             {
  35.                 print("Spawning rock!");
  36.                 spawnTimer -= 5;
  37.  
  38.                 GameObject newRock = (GameObject)GameObject.Instantiate((UnityEngine.Random.value > 0.5) ? rock1 : rock2);
  39.                 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.             }
  44.         }
  45.         else
  46.         {
  47.             spawnTimer = 0;
  48.         }
  49.  
  50.         base.OnFixedUpdate();
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment