function call inside OnClick Event?
I'm working with an Event System trigger on the 2d app. I was finally able to get the triggers to work onEnter, onExit, and onClick. With the onClick, I wanted to bring up a dialog box to confirm the selection( in this case to delete the item selected.) For whatever reason, the dialog function is not called.
public void GoEnter()
{
Debug.Log("you entered");
IDText = MemberID.GetComponent<Text> ();
IDText.color = Color.red;
NameText=MemberName.GetComponent<Text>();
NameText.color=Color.red;
}
public void GoExit()
{
Debug.Log("you exited");
IDText.color = Color.white;
NameText.color=Color.white;
}
public void GoClick()
{
IDText = MemberID.GetComponent<Text> ();
IDText.color = Color.green;
NameText=MemberName.GetComponent<Text>();
NameText.color=Color.green;
Debug.Log("you clicked");
DeleteWindow();
}
You are allowed to call functions from inside an OnClick, OnEnter ... . They work the same as calling any other function any other time. So that's not the problem.
Well, the OP wrote that onEnter and onClick were working, so they must have been spelled correctly, etc... at one point (but who knows.)
Q's like this, you pretty much have to walk someone through the whole process. For example, the title is about a function call from OnClick, but the code below shows a completely different thing. So you know you have to start from basics to find the problem.
Answer by Gilead7 · Feb 10, 2016 at 01:03 AM
Come to find out, if you change the event to OnClick, OnEnter, OnExit, you do not need an event system added in. That does solve one problem, but I still cannot call any functions outside of this script. I added the reference at the top, but I get a null reference every time I try to access it. For whatever reason, it will not let me put anything(script or game object) into the public reference in the inspector. I don't get it! Please help! Save my sanity!
public Script2 _script2; --reference to test script
public void OnClick()
{
IDText = MemberID.GetComponent<Text> ();
IDText.color = Color.green;
NameText=MemberName.GetComponent<Text>();
NameText.color=Color.green;
Debug.Log("you clicked");
_script2.HelloScript2();
}
Script2
public void HelloScript2()
{
Debug.Log("Hello Script 2! This is Script 1 Calling!");
}