- Home /
Question by
ragefordragons · Apr 28, 2017 at 06:02 AM ·
errorbooleanbooleans
Booleans are "asssigned but never used"???
So I am trying to create a boolean that judges wether or not the player is in a box collider. Although, it dosent work because the booleans have this error message: "the variable "hitbox" is assigned but never used." Can anyone tell me why?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class gunpickup : MonoBehaviour {
public GameObject pickuptext;
public bool hitbox = false;
public GameObject tablegun;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.E))
{
if (hitbox == true)
{
tablegun.SetActive(false);
}
}
}
void OnTriggerEnter(Collider col)
{
pickuptext.SetActive(true);
bool hitbox = true;
}
void OnTriggerExit(Collider col)
{
pickuptext.SetActive(false);
bool hitbox = false;
}
}
Comment
Best Answer
Answer by tanoshimi · Apr 28, 2017 at 06:15 AM
Because you declare a class-level variable called "hitbox" on line that's never used. In your OnTriggerEnter and OnTriggerExit you declare additional local variables also valled "hitbox" rather than setting the value of the existing one.
What you meant to do was this:
hitbox = true;
and
hitbox = false;
not
bool hitbox = true;