Friday, October 14, 2022

Hey! 
Long time - no post. What's up with you? I hope you are doing well. Things are looking a lot brighter for me these days. I am getting medicated and all that jazz.

I started writing a note to myself this morning and decided to expand that out to a blog. I hope it brings some joy. It has been a while since I've written anything like this so please remember that feedback can help! Or maybe just drop your favorite past time in the comments below, whatever you feel up to. <3 

I'm currently doing a thing where I used notepad++ to store a bunch of links instead of bookmarking them in a folder. This way I can write little paragraphs about them for later to help with the why I thought it was useful. There is probably a better way to organize, but I'm working on those skills.

I was trying to figure out why there are so many pitfalls and/or traps on the path to learning new things? Is this just a programming thing? Is there a way to avoid these things? Could I learn more things and more quickly if I had a better methodology? 

The issue that I ran into was that I making a system where the enemy objects would change color based on their current health. I thought I could modify older code that I had written for another project. So- Super Easy barely and inconvenience. I grabbed that code, modified it and slapped it in. And then:

The compiler errors started happening.

Earlier in the day I had started working on SetColor() method that I thought was going to be really difficult or take a lot of time to figure out. I was even having a laugh about the unity documentation and the impenetrable page for Gradient.Evaluate. And then it kind of just worked, so I jumped onto trying to get the next bit working. 

It is funny how things can seem like they are going to be impossible and be simple and then "simple" things turn out to be anything but.

I was trying to get one script to interact with another. For the non-coders I was basically trying to get two text documents to look at each other and be able to make reference to each other. I felt like I had to have done that in a lot of other projects. I remembered a project that I knew needed to pass a few pieces of information into another object.  

I'm putting that code here if you are interested in that sort of thing. I appreciate you for reading my thoughts and hope you are having a great day. Maybe imagine a big warm hug or sitting next to a campfire on the perfect night.  


Boring code stuff here

In this snippet I am making an object with the instantiate. And then I'm running a method in another script. 







This is the rest of the method. This is where all of those values that are getting setup. This is probably not the right way to do that part either, but it was the way that worked. 

















Well kind of worked. It forced me to make everything that it interacted with static in the Bullet script.















I attempted to just move everything into static in my new project's scripts, but that just kept cascading and I felt like that was the wrong way to do it. I couldn't figure out a way to get the component and have it work. 

Unfortunately I didn't save my attempts (normally I just comment them out, but this time I guess I deleted them). 

But I continued to google it and to read forum posts, I think I probably watched a video or two, just trying to understand what I was missing. 



Then I found this post


  1. GameObject newObj = Instantiate( ... ) as GameObject;
  2. YourScript script = newObj.GetComponent<YourScript>();
  3. script.YourPublicFunction();
Just fill in the instantiate function, and replace "YourScript" and "YourPublicFunction"
________

These simple looking 3 lines of code were all it took.

Instead of just instantiating an object this code also holds onto information about the object and then runs the script from that object that it kept a handle on. Now it doesn't require everything to be static. I'm still not sure I fully understand static. I think it has to do with where it puts it in memory and that it only creates one, where all of these other objects can be instanced meaning that you can copy them more easily. 

Anyway that is all the code. Welcome back.

I just don't know how to go about doing it wrong first. Especially when it is so difficult to understand the documentation for csharp and unity. Perhaps I should have worked on some sort of prerequisite knowledge first? I really don't know. I am trying my best and hopefully will have a game, albeit a simple one, but one that I created at the end of this. 

I am trying to improve a few different skills all at the same time. I'm trying to be the best person I can be. I will try to continue writing my thoughts. I hope you have a wonderful day. Thank you. 

-Michael