#Hey there, I've created a heart system
1 messages · Page 1 of 1 (latest)
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
healthSystem heartComponent = newHeart.GetComponent<healthSystem>();
heartComponent.SetHeartImage(HeartStatus.Full);
hearts.Add(heartComponent);
}
public void DrawHearts()
{
ClearHearts();
int heartsToMake = PlayerController.maxHealth;
for (int i = 0; i < heartsToMake; i++)
{
Debug.Log("Drawing a heart");
CreateFullHeart();
}
}
public void ClearHearts()
{
foreach(Transform t in transform)
{
Destroy(t.gameObject);
}
hearts = new List<healthSystem>();
}
}
What line has the error
1sec I'm figuring out the posting code stff
NullReferenceException: Object reference not set to an instance of an object
healthBar.CreateFullHeart () (at Assets/Scripts/healthBar.cs:36)
healthBar.DrawHearts () (at Assets/Scripts/healthBar.cs:49)
healthBar.Start () (at Assets/Scripts/healthBar.cs:16)
this is the first script I've posted that's giving the error
as visible in this screenshot references for heart prefab and player controller are set correctly
oh I see, I'll look at that now, appreciate the help, will come back if I run into more errors.