So I'm really close to getting weapons finished, finally! I think just one more day to get some more HP stuff working and clean up a few things, and boom done. Then I can start working on AI then I have my first build out. This one I'm going to make public to help get people interested. After this build though I'm only going to put out builds to people on my patreon
so after this build comes out, go check it out if you want more. The animation stuff I did was mostly gui stuff in unity, so let's cover how I got HP showing and maybe something else.
private float ToolTipCounter;
public float ToolTipMax = 1;
private string ToolTipText;
public GameObject ToolTipGuiRef;
private GameObject ToolTipGui;
So these are the variables I'm using to get the tooltip to show up. Before we jump into how they are used let me explain. ToolTipCounter is just a counter, ToolTipMax defines, in seconds, how long for a tooltip to show up, because that is public I can change it from within unity without having to rebuild. ToolTipText is just text for ToolTipGui, ToolTipGuiRef is just the reference to the game object so I don't have to do a resource.load thing, and ToolTipGui is the copy created.
ToolTipCounter = 0;
if(ToolTipGui != null)
ToolTipGui = null;
ToolTipCounter = 0;
So because both connectors and segments are 2D Box Colliders marked as triggers these methods work. When the mouse enters we just set the counter to 0. When the mouse leaves we set the counter to 0 and remove the tooltip if it's there.
if (ToolTipCounter >= ToolTipMax && ToolTipCounter != -1)
ToolTipGui = Instantiate(ToolTipGuiRef);
var pos = ToolTipGui.transform.position;
pos.x = transform.position.x + 5 + ((RectTransform)ToolTipGui.transform).rect.width/2;
pos.y = transform.position.y + 5 + ((RectTransform)ToolTipGui.transform).rect.height/2;
ToolTipGui.transform.position = pos;
ToolTipCounter = -1;
ToolTipGui.GetComponentInChildren().text = HP + "/" + MaxHP;
if (ToolTipCounter < ToolTipMax && ToolTipCounter != -1)
ToolTipCounter += Time.deltaTime;
I guess this is the meat of things. Honestly getting the tooltip up and running was pretty easy. At first I wanted to just have the tooltip show up on the mouse, but Input.MousePosition gets the mouse position in pixels and was a bit of a pain. I kinda like this better, instead it shows up on the corner of the thing you are hovering over. I'm going to have to change it tomorrow, but for now you can get the idea. So we check if the counter is greater than max and the counter isn't -1. If so we then make a new ToolTipGui, set it's position and text, as well as set the ToolTipCounter to -1. Then we check if the ToolTipCounter is less than the max and not -1, then we just add the Time.deltaTime. Time.deltaTime is a float that counts in seconds since the last frame. So the reason for the whole -1 thing is we don't want to keep making tooltips if one is already made. I could've used a boolean but I didn't want to.
Also today I cleaned up some of the weapons and system code. I figured a lot of it could be cleaned up and made easier to follow. Another thing I did in the weapons code was taking out to check if it was occupied or not every frame. Because we are calling a method when it becomes occupied or someone leaves I could just piggyback off of that method and it makes more sense.
public override void Disable()
Disabled = true;
CurrentReload = 0;
ReadyToShoot = false;
WeaponArmed.sprite = Resources.Load(@"Sprites/WeaponNotReady");
ReloadSlider.value = 0;
So here is the code for making a system disabled. We are just setting everything back to 0 and setting Disabled to true. In the update method it checks if disabled is true or false, if it is true(disabled) then it won't do anything. I haven't written any code to enable a system yet, but I'll have to once I get repairing into the game. I think after AI I'll work on repairing segments and connectors.
Guess that's it for today. If you didn't know I upload the streams to my youtube
in case you wanted to watch the streams but missed them. I created a playlist
too. Tomorrow we are going to get ship damage working, clean up code for connectors and segments, and get HP showing for the ships. I don't think that will take long so I might finish up the stream by just cleaning up so code so it doesn't become too big of a mess.