I was trying to convert my application to mobile, and have encountered a serious problem with the touch interface (Using Raycast).
While working very well with a normal scene (picking objects ecc), when implementing the exact same code into a scene that imports asset bundles, it stops working. Touch works on GUI items, but not on the 3D objects I need it to work on.
Here’s my code:
#pragma strict
var Target : GameObject;
var TargetGrabFunction : GrabNRotate;
private var cam : Camera;
function Start(){
cam = Camera.main;
}
function FixedUpdate(){
if (Input.touchCount > 0)
{
var theTouch : Touch = Input.GetTouch (0);
var ray = cam.ScreenPointToRay(theTouch.position);
var hit : RaycastHit;
if(Physics.Raycast(ray,hit,100))
{
if(Input.touchCount == 1)
{
if (theTouch.phase == TouchPhase.Began)
{
Target = gameObject.Find(hit.collider.gameObject.name);
TargetGrabFunction = Target.GetComponent(GrabNRotate);
//using 0, 1 and 2 for my boolean cos I need 3 states of true and false
if((TargetGrabFunction.bringOver==0 || TargetGrabFunction.bringOver==2))
TargetGrabFunction.bringOver = 1;
else
TargetGrabFunction.bringOver = 2;
}
}
}
}
}
Basically, this code is supposed to enable another external code on the gameobject when it is touched.
It works fine on an empty scene with only the gameobject.