Now, in the hierarchy this is what we have (minus me having them prefabbed already):
So, shouldn’t the GetChild() of the current slot index already give us the InventorySlot which is exactly the object that has the InventorySlot component on it?
So why should we have to do a GetComponentInchildren<>() to grab it, then?
I would think GetComponent<InventorySlot>() would be perfectly fine…
For some reason I also can’t even do that first swing down of the sword. I can run around and hit things though, as the weapon’s collider is active when the weapon gets spawned…
I hope that will be cleared when finishing the second half of this part and all the interactions between player and sword have been rebuild…
You are absolutely correct and when we do the null check before we dont need to be checking the children either as GetComponent would suffice. I’ve given Stephen the heads up on this.
I’m not sure why your first swing is not working as it should be working at the end of this lecture.
I am guessing it worked before we switched weapons so if you could post your code and we can take a look as a second pair of eyes can often spot issues (I have to get my wife to look sometimes although most of the time her reply is “Did you forget a semi colon” >.< Shes not a coder!)
I dont think i have seen your itch page or if i did my memory is failing me.
If you can let me know where i can try to get a look in before the weekend
But, traversing through the object hierarchy like that is somewhat brittle since it would break on any seemingly minor re-arrangement of the object hierarchy, and the following lesson will surely get to a much better solution that will survive more than one swing…
I still wonder why the projects would deviate in a way that would make it work in the course and fail for me…
We’ve added an edit to the video to explain although we can just use GetComponent and probably should GetComponentInChildren will work as it checks the top level and down the heirarchy until it finds it or reaches the end.
At the end of the day GetComponent is probably more efficient though