Help with code Error null reference and namespace?

Hi all to those who help or read,

Were am I going wrong with this ?

I know you said about Character as not a MonoBehaviour; but it is part of my script and gameobject ( i might not be explaining my self well) so please bare with me.

[code=CSharp] using UnityEngine;
public class Player : Character {
  // some other stuff, whatever may already be in the class
  void OnTriggerEnter2D(Collider2D collision)
  {
    if (collision.gameObject.CompareTag("CanBePickedUp"))
    {
Item hitObject = collision.gameObject.GetComponent<Consumable>().item;

if (hitObject != null)
print("Hit: " + hitObject.objectName)

switch (hitObject.itemType)
{
     case Item.ItemType.COIN:
        break;
        AdjustHitPoints(hitObject.quantity);
         break;
        default:
        break;
}
      collision.gameObject.SetActive(false);
    } //closes the if statement
  } // closes the method
} //closes the class

public void AdjustHitPoints(int amount)
{
hitPoints = hitPoints + amount;
print("Adjusted hitpoints by: " + amount + ". Newvalue: " + hitPoints);
}

[/code]

this is what the book said:

My issue is that im not good at coding, therefore i put things in the wrong place at times. so if you can guide me.

Thank you in advance.[/QUOTE]

With programming 100% of all things must be spelled properly, capitalized properly, and the punctuation must also be perfect.

There is unfortunately no room for wiggle on this.

I suggest you step back and try a tutorial that includes the code you need, until you get a feel for what it should look like and how to get it 100% perfect.

1 Like