- Home /
Input across scripts
Hello. I have been trying to read input from a ui. Basically, I want my camera to know when a gameobject with a guitexture has been touched ( I am developing for mobile, more specifically, ios). My guitexture knows when it has been touched, but I need a way to send the information that the gameobject has been clicked across scripts. Do I use a global variable? My script is in c#, named Test, and is:
using UnityEngine;
using System.Collections;
public class Test: MonoBehaviour
{
void OnMouseDown()
{
Debug.Log ("Mouse Down");
}
void OnMouseUp()
{
Debug.Log ("Mouse up");
}
}
I would appreciate it very much if someone could explain how I would go about doing this. Thank you for your time! (Note: jump-ui is the empty gameobject)
Answer by getyour411 · Jul 29, 2015 at 05:32 PM
There are many examples on UA that show how to do this. You might add
public SomeClass someClass;
to the top (above OnMouseDown/first method), which will expose a field in the Inspector that you can drag/drop the other GameObject you want to notify that has SomeClass component attached. Then, in your OnMouse event you can
someClass.someMethod(aParameter, bParameter);
someClass.someVar = 1;
This is pseudo code don't copy and paste it
http://answers.unity3d.com/questions/10857/how-can-i-access-other-scripts-and-their-functions.html
Your answer
Follow this Question
Related Questions
iOS touch recognition on UI has odd delays 1 Answer
Change Player object at touch 1 Answer
Check UI panel touched after OnEnable()? 0 Answers
How to get PointerEventDatas[]? 0 Answers