hello im begginer in C# and unity. i cant assign a boolean value to the IsShieldNull method
it writes that it is null. can you help me pls? i spend 2 days for this problem and cannot fix.
error message - (NullReferenceException: Object reference not set to an instance of an object)
Thanks.
here is my main code.
public class PlayerManager : MonoBehaviour
{
public PowerUpShield ShieldPowerUp;
void Start()
{
ShieldPowerUp.GetComponent<PowerUpShield>();
}
void FixedUpdate()
{
if (ShieldPowerUp.IsShieldNull() == true)
{
if (Input.GetKey(KeyCode.C))
{
Shield.SetActive(true);
}
}
}
}
and my second code from where i want to use variable boolean.
public class PowerUpShield : MonoBehaviour
{
public GameObject IsPowerUpAnimation;
public bool IsNull;
void Start()
{
IsShieldNull();//tryed to summon method here to assign.. but no result.
IsNull = false;
}
void OnTriggerEnter2D(Collider2D Trig)
{
if (Trig.gameObject.tag == "Player")
{
IsNull = true;
Destroy(gameObject);
IsPowerUpAnimation.SetActive(true);
Destroy(IsPowerUpAnimation, 1.5f);
IsShieldNull();//tryed to summon method here to assign.. but no result.
}
}
public bool IsShieldNull()
{
return IsNull;
}
}