When we got to the challenge section of this lecture, I was a little confused how to replicate the InteractWithCombat() method because I thought, “why on earth would I need to use a for loop for movement? There’d be endless RaycastHit hits!” So like a real noob programmer, I started writing a foreach loop for InteractWithMovement() anyway, copying InteractWithCombat()'s code almost line-for-line, spending a half-hour wondering how to get the damned thing to work.
Then, it occurred to me—why not just use the variables from MoveToCursor()?
But Tryndamere, how do I use variables from another method? If I just steal them, I have redundant code, and there’s something I ought to do about that, right? I asked myself the same thing, so I just ripped the variables from MoveToCursor() and tried to figure things out from there. I kept getting stuck, though, thinking it would be better to make MoveToCursor() into a bool as well. So I erased the stolen variables I put in InteractWithMovement() and put them back into MoveToCursor(). I tried setting the value of InteractWithMovement() in here, and realized that didn’t work.
I even tried to do some fancy work with GetMouseRay() inside of InteractWithMovement() to see if I could cheat the system, see if I could access the NavMesh and detect if the mouse ray collided with the NavMesh, and if not, return false. I remember frantically googling “is navmesh gameobject unity” until I realized a NavMesh is static and can’t be declared as a variable anyway. The last thing I tried was returning to the foreach loop and replacing the CombatTarget target variable by making a GameObject destination variable and checking if a ray passed through that, but still no dice.
No matter what I did, when I played the game, I saw Nothing to do. for what seemed like days, endless streams of inaction and confusion. I was all over the place with it, coming up with complicated solutions that teetered on the edge of getting it, coming so close but feeling so far away. I
And so I checked the video for hints. Who knew it would be as simple as just removing the MoveToCursor() method entirely and using its code for InteractWithMovement() instead? Golly gee, I hope I can figure things out better in the future, because I felt pretty dumb after that one.