var Active : boolean = false;
function Update ()
{
var Dissable_button : Dissable_button = GetComponent(Dissable_button);
if (Input.GetKeyDown ("escape")){
if (Active == false){
animation.Play ("A_in");
Active = true;
Screen.lockCursor = false;
Dissable_button.Toggle(); //Acsesses script B's Function
}
}
}
function Close ()
{
animation.Play ("A_out");
Active = false;
Screen.lockCursor = true;
Dissable_button.Toggle2(); //Acsesses script B's Function
}
Then there is script B
private var button : UnityEngine.UI.Button;
function Start ()
{
buttont = GetComponent(UnityEngine.UI.Button);
}
function Toggle () // The function script A is calling
{
button.enabled = !button.enabled;
print("Toggled!");
}
function Toggle2 () // The function script A is calling
{
button.enabled = !button.enabled;
print("Toggled!");
}
The to scripts are in two different objects. Script a is calling function’s in script B.
Why is it not working.
When you use ‘GetComponent(Dissable_button)’ that would only work if both components were in the same object. If script B is in a different object you would need to do something like this in Script A:
var Dissable_button : Dissable_button = ObjectB.GetComponent(Dissable_button);
‘ObjectB’ would be a GameObject in Script A that you would set to point to the object that contains Script B.
var Active : boolean = false;
function Update ()
{
var Dissable_button : Dissable_button = transform.GetChild(2).GetComponent(Dissable_button)();
if (Input.GetKeyDown ("escape")){
if (Active == false){
animation.Play ("A_in");
Active = true;
Screen.lockCursor = false;
Dissable_button.Toggle(); //Acsesses script B's Function
}
}
}
function Close ()
{
animation.Play ("A_out");
Active = false;
Screen.lockCursor = true;
Dissable_button.Toggle2(); //Acsesses script B's Function
}
Now I am getting the error | Assets/Pause_menu.js(4,91): BCE0077: It is not possible to invoke an expression of type ‘Dissable_button’