I was
on vacation again this week so I didn’t really do a lot. Aside from show off
the game to various different people who I could subject it to. I did however
get a working primary attack set up. Last week I set up some targets that would
take damage when hit but any of my secondary weapons. This week I set it up so
the targets will die after they run out of hit points. The targets are supposed
to give the player ammo when they die but I didn’t have a set up for player
ammo being deduced when a secondary weapon was used. I added a player ammo
counter and a restriction that prevents the player from using a secondary
weapon if they don’t have any ammo. Once that was set up it was pretty easy to
add into the on death for the target to give the player ammo when the target is
destroyed.
Next
week I need to add in a basic UI for Player; health, current secondary weapon,
ammo and can teleport. I also wanted to make a video of what I currently have.
But I think that may have to wait until next week. It hasn’t really been a big
week but I did get more done than the last time I was on vacation.
Hey
look it is next week. I didn’t post this last week partly because I was on
vacation and partly because I didn’t have a lot to report. I kind of still don’t
BUT I did add in all of the UI elements for Player stuffs. I did find some
small bugs with my can teleport bool. Basically if my top raycast is not
touching collision but the bottom raycast is touching collision the can
teleport bool is true BUT the player can’t teleport. Super minor. It is
certainly something that needs to be fixed but for the most part it works. The
issue is clearly not with the UI and more with the teleport testing method I’m
using. I need to change this test to an onOverlap instead off of four rayCastHit.
So I’m
going to complain about getComponent call once again SHOCKING I know. To make
my UI work I have four Canvas elements that each monitors four player
variables. I have seen on the internets in my research on this topic that you
should never use a getComponent call every frame it will slow your game down. This
was the only way I could figure out how to get the UI to update when the player
variables changed. However there was no slow down when all of them were
updating. Basically my update for UI stuff looked like this:
Update(){
GameObject thePlayer = GameObject.Find("Player");
Player playerScript = thePlayer.GetComponent<Player>();
displayPlayerAmmo.text = playerScript.playerAmmoCount.ToString();
}
Again I
have been told that this is terrible but various Unity people on different
Unity forums. But how am I supposed to display and monitor variables from the
player in the UI canvas? No seriously how does one do this? I had a thought and it was this:
Update(){
If (hasGotten == false){
GameObject thePlayer = GameObject.Find("Player");
Player playerScript = thePlayer.GetComponent<Player>();
hasGotten = true;
}
displayPlayerAmmo.text = playerScript.playerAmmoCount.ToString();
}
However
THAT doesn’t work because GetComponent call only seems to pertain to the method
you are currently in. Meaning that Update doesn’t know about playerScript. Only the nested If statement knows about the playerScript.
The wife
goes back to work next week and I will have less time to devote to this thing.
So my Updates might be shorter. I think I need to switch to working on more of
the artwork as that is something I can do at the same time as being a stay at
home parent much easier than programming.
No comments:
Post a Comment