Just a small scripting error

I am currently creating a script where when a player gets hit he will lose some health then once he has lost all his health he will be respawned, although i am getting this error somewhere along the line "Cannot implicitly convert type ‘HealthManager’ to HealthManager’ the error is on line 23 of the LevelManager script.

(I am new too coding but i have 2 scripts which i believe one of them is most likely causing the error.

HealthManager: using UnityEngine;using System.Collections;using UnityEngine.UI;public c - Pastebin.com

LevelManager: using UnityEngine;using System.Collections;public class LevelManager : Mon - Pastebin.com

Any help would be great thanks.

FindObjectsOfType returns an array of all active loaded objects that match a particular type (notice the plural ‘s’ of Object(s) in the function name. So, the healthManager variable can hold a reference to a single HealthManager type object but you are passing an “array” type, which just happens to hold HealthManager objects. Hence the error “Cannot implicitly convert type… (meaning cannot convert array to HealthManager)”.

However, that’s just part of the problem. Even if you use the function FindObjectOfType (no plural ‘s’ here), which returns the first active loaded object of a particular type, you will still get an error, because the function returns an “object” which has to be casted to a HealthManager type, before it can be assigned to the healthManager variable.

Anyway, this is the code you should replace line 23 of the LevelManager script:

healthManager = (HealthManager)FindObjectOfType<HealthManager>();