Jump to content

TheMightySpud

Members
  • Posts

    30
  • Joined

  • Last visited

Everything posted by TheMightySpud

  1. Thanks for the responses guys, really appreciate it. I've updated my code a little, and finally figured out I was using the wrong debug window *dumbass* lol. I was using the one in the Alt+F12 menu, but discovered the Alt+f2 window this morning, which is far more helpful. So the code is here, the problems are listed below (there is only one that I can see, well two, but we'll come to the second one in due time :)) using UnityEngine; using KSP.IO; using System.Collections.Generic; namespace TMS_Module_001 { [KSPAddon(KSPAddon.Startup.SpaceCentre, true)] public class TMS_Module_001 : MonoBehaviour { public void Awake() { // Create a new blank vessel Vessel newVessel = new Vessel(); // Add a part to the vessel Debug.Log("getPartInfoByName"); AvailablePart avParts = PartLoader.getPartInfoByName("GearFixed"); Debug.Log("Instantiate"); //UnityEngine.Object obj = UnityEngine.Object.Instantiate(avParts.partPrefab); if (avParts != null) { UnityEngine.Object obj = Instantiate(avParts.partPrefab, new Vector3(0f, 0f, 0f), Quaternion.identity); Debug.Log("newPart"); Part newPart = (Part)obj; Debug.Log("rootPart ; parts.Add()"); newPart.gameObject.name = "TMS_Module_001"; newPart.partInfo = avParts; newVessel.rootPart = newPart; newVessel.parts = new List<Part>(); newVessel.parts.Add(newPart); // Set vessel parameters Debug.Log("Set vessel params"); Debug.Log("-----------------"); Debug.Log("Set vessel name"); if (newVessel != null) { newVessel.name = "TMS_Module_001"; } else { Debug.Log("Vessel is Empty"); } Debug.Log("Set Landed status"); if (newVessel != null) { newVessel.Landed = true; } else { Debug.Log("Vessel is Empty"); } Debug.Log("Set Splashed status"); if (newVessel != null) { newVessel.Splashed = false; } else { Debug.Log("Vessel is Empty"); } Debug.Log("Set LandedAt status"); if (newVessel != null) { newVessel.landedAt = string.Empty; } else { Debug.Log("Vessel is Empty"); } Debug.Log("Set Landed status"); if (newVessel != null) { newVessel.situation = Vessel.Situations.LANDED; } else { Debug.Log("Vessel is Empty"); } Debug.Log("Set vessel type"); if (newVessel != null) { newVessel.vesselType = VesselType.Debris; } else { Debug.Log("Vessel is Empty"); } Debug.Log("Set vessel Position"); if (newVessel != null) { newVessel.transform.position = new Vector3(5f, 0f, 5f); } else { Debug.Log("Vessel is Empty"); } newVessel.GoOffRails(); newVessel.Load(); } else { print("Part Not Found"); } } } } After a little more poking around I decided to go with the KSPAddon bit, and the code executes exactly when I want it to, which is great. (yes I realise that my module will spawn every time I go to the space center at the moment, but I'll be adding a check to see if the object already exists when I finally get it to spawn. So onto the main problem. According to the Log, the 'newVessel' Vessel, never gets populated. As you can see I've added a bunch of debug commands to see what's going on and each line prints out the debug info (Vessel is Empty) So right off the bat there's nothing there which is stopping pretty much everything else, and I can't seem to figure out the problem. Any insight would be greatly appreciated. Thanks TheMightySpud
  2. Sooooo, I've got some code that should (and I stress should) spawn an object at run time.......logically in my head it should work, but I'm probably doing something really stupid. At the moment, if I'm reading the log correctly, I don't think this code is even running, I've been staring at it and trying various things for several hours so I would be most appreciative if someone could take a look and point out where I've been an idiot public class TMS_Module_Test_001 { public void Onstart() { // Create a new blank vessel Vessel newVessel = new Vessel(); // Add a part to the vessel Debug.Log("getPartInfoByName"); AvailablePart avPart = PartLoader.getPartInfoByName("TMS_Module_001"); Debug.Log("Instantiate"); UnityEngine.Object obj = UnityEngine.Object.Instantiate(avPart.partPrefab); Debug.Log("newPart"); Part newPart = (Part)obj; Debug.Log("rootPart ; parts.Add()"); newPart.gameObject.name = "TMS_Module_001"; newPart.partInfo = avPart; newVessel.rootPart = newPart; newVessel.parts = new List<Part>(); newVessel.parts.Add(newPart); // Set vessel parameters Debug.Log("Set vessel params"); newVessel.name = "Test_Module_001"; newVessel.Landed = true; newVessel.Splashed = false; newVessel.landedAt = string.Empty; newVessel.situation = Vessel.Situations.LANDED; newVessel.vesselType = VesselType.Debris; newVessel.transform.position = new Vector3(5f,0f,5f); newVessel.GoOffRails(); newVessel.Load(); } } As I said I'm very new to C# so not really sure what I'm doing wrong, but logically I'm creating a new vessel, adding a part, defining all the attributes of the new vessel and then spawning it. TheMightySpud
  3. Hi again all, I have another annoying question. :-P As part of my mod I'd like to spawn a bunch of Parts as vessels over the surface of a planet/moon at the games startup, I think I've got the positioning etc. all sorted in my head at least, the problem I'm having it getting things to actually spawn. :-/ I've been playing around with the ProtoVessel bits and pieces but I'll be honest, the usage and syntax is kicking my backside. I've had a poke around at the source of a few mods that kinda do something similar, but again I'm having a real hard time making heads or tails of how it all works. Could someone point me in the right direction? (Just want to be clear and say I'm not looking for someone to spoonfeed the code to me, just a general idea of where to look for answers :)) Thanks, TheMightySpud
  4. Excellent, thank you Really appreciate you taking the time to reply Next problem I'm having is how to assign my object to 'YOURTHINGY' in the 'YOURTHINGY.GetWorldPos3D()' part. :-/ Seems like it should be a very simple thing, but having a devil of a time figuring it out. Reading lots, but not really making a lot of sense to me. lol. Thanks TheMightySpud
  5. Hi all, Been poking around here for a while, and have started on a mod (which for the moment is a secret....sssshhhh :-P) I'm making really good progress so far but I'm very very new to c#, I have some knowledge of vb.net, so the translation isn't too hard so far. Chances are I'll have a few more questions on how to do a couple of things I need to do, but for now I'll start with....... What I have at the moment is a bunch of objects spread around Kerbin and what I would like to do is get the straight line distance value between a Kerbal and the closest of these objects (all of the objects will be identical, so I'll also need a way to identify them, but I assume there will be a method to add a 'tag' or something to said objects, so not worried about that for the moment :)). The idea being that when said Kerbal is within a certain distance of this object a GUI window pops open. Would anyone be able to point me in the right direction as to what to use to get this number? Thanks TheMightySpud
×
×
  • Create New...