top of page
Search

Proof of Rob's existence

As much as for Rob's benefit as it is for mine, might as well blog out my progress so far with "Space Rob and the Thought Planet".


To preface that the ground works were greatly aided through learning from a book, "Learn Unity for Android Game Development" by Adam Sinicki (many thanks Adam!), so I didn't note down my progress during such: we instead start our thrilling updates from when the book has been concluded, and the scary world of independent thinking begins.


Sadly, and also to conveniently pooh-pooh away the massive gaps between my small bouts of activity, I cannot recall the date of the updates, so let's just happily cram them all together!


Update 0:

The platformer's concept will be simple: astronaut landed on alien planet, needs to escape. The controls will be the gimmick: three/four speech bubbles at the bottom of the screen, which you need to tap to do actions -eg. press the jump one to jump. Once pressed, the thought will be replaced with another one, rinse and repeat.


Is this duable? I mean, graphics/etc. will be simple, but the controls...essentially touch-based, they'll just be buttons with different graphics, that once tapped, or perhaps after x time, are replaced by others -randomly, or certain buttons bring on certain others.


So, in essence the left/right/jump controls, just need to be replaced with speech bubbles, which become the controls -pressing one is then linked to a specific thing (move right, jump, etc).

It must be relatively possible to not only make the buttons disappear, but then cycle to another one -or, would static buttons remain, but the text change inside of them?

Hmmm...at least some animation with the buttons is required (although if too hard, can skip), especially in terms of telegraphing when the button is about to disappear.


Would be awesome if thoughts could be discarded and not selected, say with a swipe gesture, but depends if thats too much hassle.

Big thing to consider as alluded, is how the thoughts are generated: will they all be kept in a class, then pulled depending on the level? Pulled at level load, or pulled when asked for? Must be latter, but then are they what, instantiated, or is the button etc. already set up as a prefab, then called/visibility and position modified? Hm.


Im assuming if as a prefab that's a fair bit of extra overhead: there again, specific levels will have only specific elements, but nevertheless it would bloat out the whole project.

Instantiation on the other hand...I mean, the methods would be stored in the class, and really there's only need for a few thought prefabs as they can all be the same shape&art, but the words inside are the important thing -can they be instantiated/pulled as part of the method?

I think before going any further, I need to try and create even just one thought button, to see how feasible this is.


So, the first thing we try, is whether I can make a command code that creates a thought instance: it would be like the bullet from the teaching book, right? Just press a key, generate bullet, happy days. In fact, perhaps just put the code in the bullet script, see if it makes it appear.

My concern though is that it will appear, but not as an UI element -undoubtedly that can be done, but im not sure yet how, so let's google...


Update 1:

I can instantiate the image as a child of the canvas! Now, I need to apparently make "world position" false, or maybe I'm over-thinking it, and just need to put "false" at end of instantiate script. Same for the parent class, just have the name (comment: I'm honestly not sure what Iean about the parent class here, apologies.)?


Update 2:

Well, that worked -but I can't honestly say I get its use. But then, in my research I see a "layoutgroup" mentioned in the Unity how to, and now I'm tinkering with a whole new way of dynamically placing UI elements, which is hopefully exactly what I need! Slight snag: from the video, I cannot find the UI-create button part in my copy of Unity, closest is one with mesh pro.

Is it because i chose a basic 2D scene? I'll try it with the 3D one -although, video is using 2019 Unity rather than the 2021 one.


Update 3:

Bizarre. Button option is no longer there in Unity, guess we'll need to create a text mesh pro button! Need to do it with wifi though, as it's saying to download stuff.


Update 4:

Well, I've done the script as per the video, and it kinda works. Kinda, because it will not change the text on the buttons! Unity gives me a "object reference error" -which looks like it's to do with the "getcomponentinchildren" not pulling said component.

I've seen online this command written as "getcomponentinchildren<Text>.text", perhaps I need to add the .text? No, that's just to define it as part of "getcomponent".

Wait a tick: is it perhaps the text name -I'll try using "<TMP_Text>".


Update 5:

It worked! Issue was that the textmeshpro assets weren't being firstly called into the code! Added this using TMPro, changed created text to TMP_Text, component pulled something mesh, voila! Now...what to do with all of this??

So, we have a way of neatly storing and displaying buttons, and a way of changing text on said buttons. Let's turn this into the GUI of three thought buttons, see if we can even display it properly.


Which will need...I mean, all I need to do to start with, set the displayed buttons to three, load up relevant images for them, and change the text that is to be displayed, right?


Update 6:

Hmmm...so, "inventoryitembutton" class determines the name change of the buttons... so, surely I need a sort of masterclass which holds all button names? Can even be a different string per level, and essentially that string then gets loaded for the relevant level.

I'd also need another class with all the behaviours -as in, what each text does...but yes, sorry, need to create the three thought buttons first.


Update 7:

Well, trimming down the buttons to three and replacing with the thought images was easy peasy, understandably. Changing what word is displayed at runtime, which for now are "run, jump, stop", also a similarly straightforward coding change.


However, how are the buttons in the inventoryDisplayControl able to interact with the buttons in the inventoryPanel? I mean, I get it that on click, they call the ShowOnly() method from the inventoryDisplay script, which in turn pulls the InventoryItemButton script, but how does that figure out the word that is to then be showed?

It would be advantageous to understand this fully before continuing, for learning purposes.


Update 8:

Ok, it was an easy one: the inventoryItemButton script is attached in Unity to each button game object, which are childrens of the "InventoryPanel" object, and since the "InventoryDisplayControl" points towards the script (BUT, this is done by pointing towards the object, THEN, selecting the script within the object as the onclick function), it all links together.


OK, that's great, sooo...what I want, is the thought buttons, onclick, to point towards either an object or a script, that changes their text...so, I need a script to do that, right? A changeText script? And randomly, so it would then function very similarly to the "InventoryDisplayButton" one??


Curious: I'm having difficulty running the script from onClick. I mean, I can link it, but it won't run it -to note, I'm trying to run the entire script on click, rather than just a function within it, and im pointing to the script directly rather than a gameobject with the script. Surely, one can run the whole script?? Or, does it need to be nested inside an object beforehand?


What about...if it points to its own object, and pulls the script from itself: would that then only modify its own text?


Update 9:

Well, that worked -just put the script inside the thought button gameObject, onClick point to itself (and make sure the script's Awake function is public), select Awake and voila, randomly creates a new word on click!

It's still awkward -for eg. it may re-make the same word several times on multiple clicks, which of course you may not want to select, so we'll need to eventually add swipe commands to change a thought without selecting it -or, put some sort of coding filter to not have the same text repeated.


Anyway: this is all very good, but it needs adding inside one of the levels!

That was thankfully quite easy: just put the whole inventoryDisplay in the Unity prefabs, then drag said prefabs into the main level canvas (making sure you open the canvas prefab first, otherwise it won't let you), and now the buttons appear on that canvas!


Soo...next stop, I guess map the button's word to making Rob make an action? Likely it'll be the integer that is linked to the word, rather than word, but the outcome should be the same. Should be simple enough with an IF statement, then it pulls the function from the Player class?

Probably start with making him jump.


Update 10:

Well, the groundwork I did with that learning book is sure paying off! Again, easy: reference the Player game object and thusly the script, where all the movement stuff is, then IF typeIndex is 0 (which is the integer assigned to the Jump word), pull the jump method.

Now, I attached this to the onClick event for each of the thought buttons (in essence, on click it looks for the method just created, which is attached to each individual thought button), and sure enough, on clicking a thought with the Jump word, Rob jumps!


Then, getting the word to change should be easy enough, just need to invoke the Awake method of the same script, which will re-set the typeIndex for that specific button.


Two things:

1) Does onClick work for touch controls? I know that I've created a separate Touch script when doing the book learning, to ensure touch control works...but, it seemed a bit wasteful to add onto the thought gameobject an event trigger that would use pointerDown, when the game object is already a button, and has an onClick event...need to check if the latter works with touch, otherwise I might just remove the button component...no, I can't since it lets me dynamically change the text!

Then, I'll just add the extra event trigger?


2) When the button's text changes, there will need to be some sort of graphical transition to help recognise this. A text fade, or some such, especially if the same text as before returns. There again, surely I need to force the next text to not be exactly the same?

Or, would that be ok, since It'll add to the possible francticness of trying to get rid of the unnecessary thought and align the right one?

 
 
 

Recent Posts

See All
Do it the Sims way.

Sims 4 is on Game Pass, so we rejoiced. Not with wild, uncontrolled euphoria, mind you: just a little thrill of excitement at getting to...

 
 
 

Comments


Post: Blog2_Post

Subscribe Form

Thanks for submitting!

  • Facebook
  • Twitter
  • LinkedIn

©2022 by Star Cake Inc.. Proudly created with Wix.com

bottom of page