Not sure what you mean with that, but you can definitely use OnMouseDown to activate something when "clicked" [http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseDown.html][1]
If you mean you have code in your OnClick and want to call it with another method, you could do it like this:
Let's say you have this right now;
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour {
void OnMouseDown() // You want to call this right?
{
Debug.Log("Yay!");
}
}
To make it callable, you could:
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour {
void OnMouseDown() // You want to call this right?
{
RunCode(); // Redirect to the actual code
}
public void AccessibleMethod()
{
RunCode(); // You can call this whenever you want, programmatically
}
private void RunCode()
{
Debug.Log("Yay!");
}
}
Now you can call the "OnClick / OnMouseDown" Code programmatically too :)
I hope that helps, if you still have questions, feel free to ask, otherwise please accept this answer ;)
[1]: http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseDown.html
↧