Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Solarnrg's untested code
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using UnityEngine;
- public class MuMechModuleDrill : PartModule
- {
- GameObject rock1, rock2, rock3;
- static double spawnTimer = 0;
- public void FixedUpdate()
- {
- if (vessel == null)
- {
- return;
- }
- if (!rock1)
- {
- rock1 = PartReader.Read(KSPUtil.ApplicationRootPath + "Parts/mumech_drill/rock1/", "model", ".mu");
- rock1.name = "rock1";
- rock1.transform.position = new Vector3(1e10f, 1e10f, 1e10f);
- rock2 = PartReader.Read(KSPUtil.ApplicationRootPath + "Parts/mumech_drill/rock2/", "model", ".mu");
- rock2.name = "rock2";
- rock2.transform.position = new Vector3(1e10f, 1e10f, 1e10f);
- rock3 = PartReader.Read(KSPUtil.ApplicationRootPath + "Parts/mumech_drill/rock3/", "model", ".mu");
- rock3.name = "rock3";
- rock3.transform.position = new Vector3(1e10f, 1e10f, 1e10f);
- }
- if (drillHitTerrain())
- {
- spawnTimer += TimeWarp.fixedDeltaTime;
- if (spawnTimer >= 1)
- {
- print("Spawning rock!"); int whichrock = UnityEngine.Random.range(1,3);
- switch whichrock
- case 1:
- GameObject newRock = (GameObject)GameObject.Instantiate(rock1);newRock.transform.position = part.transform.position + UnityEngine.Random.onUnitSphere;
- newRock.transform.rotation = UnityEngine.Random.rotation;
- newRock.AddComponent<Rigidbody>();
- newRock.rigidbody.AddForce(UnityEngine.Random.onUnitSphere * UnityEngine.Random.value * 10, ForceMode.Impulse);
- spawnTimer = 0;
- case 2:
- GameObject newRock = (GameObject)GameObject.Instantiate(rock2);newRock.transform.position = part.transform.position + UnityEngine.Random.onUnitSphere;
- newRock.transform.rotation = UnityEngine.Random.rotation;
- newRock.AddComponent<Rigidbody>();
- newRock.rigidbody.AddForce(UnityEngine.Random.onUnitSphere * UnityEngine.Random.value * 10, ForceMode.Impulse);
- spawnTimer = 0;
- case 3:
- GameObject newRock = (GameObject)GameObject.Instantiate(rock3);newRock.transform.position = part.transform.position + UnityEngine.Random.onUnitSphere;
- newRock.transform.rotation = UnityEngine.Random.rotation;
- newRock.AddComponent<Rigidbody>();
- newRock.rigidbody.AddForce(UnityEngine.Random.onUnitSphere * UnityEngine.Random.value * 10, ForceMode.Impulse);
- spawnTimer = 0;
- }
- }
- else
- {
- spawnTimer = 0;
- }
- base.OnFixedUpdate();
- }
- private bool drillHitTerrain()
- {
- Transform drill = base.transform.FindChild ("model").FindChild("Cylinder");
- if(Physics.Raycast (drill.position, Vector3.forward,0.85f,1 << 15))
- {
- drill.transform.Rotate(Vector3.up * (600f*TimeWarp.deltaTime));
- return true;
- }
- else
- {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement