Public boolean can't be accessed due to its protection level.

Hello everyone,

I have two scripts, first has public bool isDead. In the second script I want to check if isDead is true or false. And that’s how I do that.

void Update(){
	if(PlayerHealth.isDead){
		//code
	}
}

PlayerHealth is the name of the script. And what do I get?

PlayerHealth.isDead is inaccessible due to its protection level

These two scripts are inside diffrent Objects.

You are accessing isDead like a static variable. Use Getcomponent from gameobject which holds that playerscript instance or set is isDead static, which i don’t suggest as its player, and is not statically living for the whole software life time.

I explain it pretty clearly in these two topics:

I would do this:

using UnityEngine;
using System.Collections;

public class PlayerHealth : MonoBehaviour {
	
public static PlayerHealth current;
public bool isDead;

void Start ()
{
current = this;
}
}

You can now access isDead wherever you like calling:

PlayerHealth.current.isDead

Also, current can say whatever you want it to say :slight_smile: