Hi guys.
I've wrote a multiTouch \ release script, which works allllmost fine .
There is one slight problem, which i think it's best if you test it out.
I'll briefly explain.
The script is attached to the camera. One public variable, that controls how many touches can the player make (It just limits the touches).
Script is sending a message to every object, that is beneath the finger and have been tagged with the tag "buttonToPress"...
Everything works just great except, that on the first object, that i touch, SOMETIMES the function is being send twice, sometimes it's send only once.... When i press on a second object (Without releasing the first one, so a second touch) message is send once.
So every first touch, the SendMessage is sending twice only sometimes, but most of the time. I have monitored it and i found, that it does send it once maybe on every 7, 8 times if i release and press.
If i am confusing you, please make that simple and quick example:
Steps To Reproduce
**1: Empty scene.**
**2: Attach the touch script to the camera:**
// Script attached to the camera supporting multi touch
// Script is sending a message, to the objects, that are hit by the ray and are tagged with "buttonToPress" tag.
// The message send is looking for a function "OnMouseDown";
#pragma strict
// Public Variables
var touchCountLimit : int = 3; // Limits the touchCount to the number specified
// Private Variables
private var selObjs : Transform[]; // Array to store the touched objects
private var fingerID : int[]; // Arrat to store the fingersID
private var fingerIdLimit : int; // The fingers ID limit for touching the objects
function Awake()
{
selObjs = new Transform[touchCountLimit]; // Limit the array
fingerID = new int [touchCountLimit]; // Limit the array
fingerIdLimit = touchCountLimit - 1; // Restrict the finger ID to the number of touches possible
}
function Update ()
{
var hit : RaycastHit; // the hit, that will store the raycast hitted objects
for (var i:int = 0; i < Input.touchCount; ++i) // Start looping through the touches
{
if (Input.GetTouch(i).fingerId <= fingerIdLimit)
{
if (Input.GetTouch(i).phase == TouchPhase.Began) // Check when TouchPhase begin
{
var ray = camera.ScreenPointToRay (Input.GetTouch(i).position); // Sends ray from the camera to the touch position
if (Physics.Raycast (ray,hit)) // Sends raycast
{
if (hit.transform.tag == "buttonToPress") // checks what the ray hit's
{
selObjs[Input.GetTouch(i).fingerId] = hit.transform; // Assign the hit object, to the appropriate array number
selObjs[Input.GetTouch(i).fingerId].SendMessage("OnMouseDown", SendMessageOptions.DontRequireReceiver); // Send message to the hit object
}
}
}
if (Input.GetTouch(i).phase == TouchPhase.Ended || Input.GetTouch(i).phase == TouchPhase.Canceled)
{
if (selObjs[Input.GetTouch(i).fingerId] != null)
{
selObjs[Input.GetTouch(i).fingerId].SendMessage("OnMouseUp", SendMessageOptions.DontRequireReceiver);
selObjs[Input.GetTouch(i).fingerId] = null;
}
}
}
}
if (Input.touchCount == 0)
ResetObjList();
}
// Resets the touched object list
function ResetObjList()
{
for (var i = 0; i < selObjs.Length; i++) // Loop through the array elements
{
selObjs[i] = null; // Sets the elements to null / empties them
fingerID[i] = 0; // Sets fingerID's to null
}
}
**3: Make one simple cube visible to camera and tag it with the tag: "buttonToPress"**
**4: Attach the following script to the cube:**
// Public Variables
public var i : int = 0;
function Update()
{
print (i);
}
function OnMouseDown()
{
i++;
}
function OnMouseUp()
{
i = 0;
}
**5: Duplicate that cube, like 2 more times and position them to be in some distance, so you can touch each of them**
**Now: When you touch on some of the cubes, it shoud be printing 1, when you release it shoud be printing 0. The problem is that the first finger touch, prints 2 most of the time, every next (2, 3, etc) fingerTouches is printing 1.
Why is only the first fingerTouch printing 2 most of the time, when it shoud be printinh 1...
P.S. Test it on Touch Device, prefferably iOS. And prefferably NOT with unityRemote, cuz it doesn't collect all touches accordingly...**
Thanks guys and sorry for the long threat... :)
↧