Hi,
Does anyone know how I can change this code so when I select an object I dont have to completely cover it with my finger and when it being dragged make it a little offset so I can see it ?
It can also be a little hard to select sometimes is there a way to fix this?
private var selected : boolean = false;
var flaskDragging : boolean = false;
function Update () {
for (var touch : iPhoneTouch in iPhoneInput.touches)
{
var ray = Camera.main.ScreenPointToRay(touch.position);
var hit : RaycastHit;
if (touch.phase == iPhoneTouchPhase.Began) {
if (Physics.Raycast(ray, hit)) {
if (hit.collider.gameObject == gameObject) {
selected = true;
flaskDragging = true;
}
}
}
//now if we move the thumb make sure our object is selected
//if so then proceed with the movement
else if (touch.phase == iPhoneTouchPhase.Moved) {
if (selected == true) {
//first we need to get the inverse transformation from the camera
//to get the correct touches coordinates
flaskDragging = true;
var cameraTransform = Camera.main.transform.InverseTransformPoint(0, 0, 0);
var touchPosition = Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, cameraTransform.z));
//get the full position from the touches
//and restrict Y axis to the actual position of the airplane = 1;
//because we only want movement in X and Z axis
gameObject.transform.position = touchPosition;
gameObject.transform.position.y = -10.5;
}
} else if (touch.phase == iPhoneTouchPhase.Ended) {
selected = false;
flaskDragging = false;
}
}
}
function FixedUpdate ()
{
if (flaskDragging==false)
{
rigidbody.AddForce (7, 0, 0);
}
}
Thanks ![]()