Question by
manzatto101 · Sep 11, 2020 at 12:15 AM ·
scripting problemscripting beginnerboolreferencingscritping
I am trying to reference a bool from another script but the only value that it returns is false
Hello, can someone help me? In my player script I have this void that changes the bool whenever I press the space bar, I call this void in the Update function. And this part is working fine:
public void ChangesWeapon()
{
if (Input.GetKeyDown(KeyCode.Space))
{
swordActive = !swordActive
}
}
I have a coin that I only want to be collected if swordActive is false, this script is attached to the Coin object in the scene.
public GameObject playerReference;
Player playerScript;
private void Start()
{
playerScript = playerReference.GetComponent<Player>();
}
public void OnTriggerEnter2D(Collider2D collision)
{
if (playerScript.swordActive == true)
{
Destroy(gameObject);
Debug.Log("You destroyed the coin");
}
if (playerScript.swordActive == false)
{
Destroy(gameObject);
Debug.Log("You collected the coin");
}
}
The collision part is working fine, but the only value that I am returning for swordActive is false and I cannot figure out why it isn't working
Comment
Your answer
Follow this Question
Related Questions
Toggle direction 0 Answers
random spawn enemy problem 0 Answers
script an delay 0 Answers
script delay ("on mouseclick") 0 Answers