DaveA
1
Please forgive if asked/answered, so many posts!
I have some in-scene (NOT GUI!) objects I need to know if the user touches (clicks).
In my Win/Mac version I have a collider on my object which repsonds to OnMouseDown
What's the equivalent for iPhone, if any? I've seen the GUI solutions, not what I need.
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 200))
{
var objecthit:Transform = hit.transform as Transform;
// What are you hitting?
if (hit.collider.tag == "3DButton") doStuff()
}
qJake
3
You can also use OnMouseDown(), which is easier, but the object has to have a collider, I believe.
DaveA
4
I wanted this to be a 'drop in' replacement for my mousehandler, so here's the script I put on my prefab:
`
function Update()
{
if (Input.GetMouseButtonDown(0)) // check for left-mouse
{
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (collider && collider.Raycast (ray, hit, 100.0))
{
OnMouseDown();
}
}
}
function OnMouseDown()
{
blah blah
}
`