I have an object with a script that has a bool variable and I want to change that variable using a script from a trigger object. So when the player enters the trigger the trigger set’s the object’s bool variable to true and when the player leaves the trigger sets it to false.
Here’s what I have so far:
public Transform target;
Void OnTriggerEnter(Collider hit){
if (hit.tag == "Player"){
script = target.GetComponent<ScriptName>();
script.boolvar = true;
}
}
Void OnTriggerExit(Collider hit){
if (hit.tag == "Player"){
script = target.GetComponent<ScriptName>();
script.boolvar = false;
}
}
the error message is saying that “script” dose not exist in the current context, but I have no idea how to declare it.