Hey guys,
got the tutorial working on my PC running windows 7 professional, unity 5.0.0.f4. everything works, food counts down, character and enemies animate correctly, enemies attack player and players animations and enemies also work. The problem is the internal walls: they are supposed to take damage, and in the OnCantMove of player, when its a wall thats passed in, when I try and cast it in Player:OnCantMove:
protected override void OnCantMove (T component)
{
//Set hitWall to equal the component
//passed in as a parameter.
if (component != null) {
// test works and the gameObject exists, so its actually there
GameObject test = component.gameObject;
if (test.name.StartsWith("Wall")) {
Wall hitWall = component as Wall;
// now hitWall on the other hand here
// is null in the debugger
===========
Its basically an exact copy of all scripts from the completed section, and everything else works. So why does hitWall return null when I attach to the process and check on it during runtime. I even tried converting Wall to a MovingObject, and after adding the appropriate code (so wall could move, but in this case doesn’t), I get the exact same error: than in Debug, when it gets to Player:OnCantMove, when the player is attempting to move into a wall, the casting to Wall fails and hitWall is null.
Also note in the OnCantMove of Enemy the Player is picked up and cast correctly:
Player hitPlayer = component as Player;
this line actually casts the Player correctly, and both animate, and the player takes damage.
Any suggestions? This code is driving me crazy!