My code for a ray that picks up an object when the screen is touched works well, but there is one problem, the screen is generally always being touched. Is there a way, so that it doesn’t count the fingers already touching the screen? Thanks a ton,
My script:
#pragma strict
function Start () {
}
var guiray : GUIText;
var flashlight : GameObject;
var flashlightdesk : GameObject;
function Update () {
var hit : RaycastHit;
var ray = camera.ScreenPointToRay (Vector3(200,200,0));
Debug.DrawRay (ray.origin, ray.direction * 10, Color.yellow);
var fwd = transform.TransformDirection (Vector3.forward);
if (Physics.Raycast(ray, hit, 100)){
// print ("There is something in front of the object!");
// var fingerCount = 0;
// for (var touch : Touch in Input.touches) {
// if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
// fingerCount++;
// }
// if (fingerCount > 0){
// print ("User has " + fingerCount + " finger(s) touching the screen");
if(hit.collider.gameObject.CompareTag("light")) {
guiray.text = "Pick Up Flashlight";
if (Input.touchCount > 0) {
//place pick up code here!
flashlight.gameObject.active = true;
//flashlight.gameObject.enabled = true;
flashlightdesk.gameObject.active = false;
}
}
else {
guiray.text = "";
}
}
}