When ever I try to use touch phases the code always happens multiple times. I would like to call a function on touch phase began only once. Instead it calls it 16 times! Any idea why? Thanks in advance
One quickie way to test for this problem in the future is to change your Debug to this:
Debug.Log(gameObject.GetInstanceID().toString + ā: Your normal messageā);
This will print out:
135829: Your Normal Message
and if you see this
124580: Your Normal Message
Then you know 2 different Game Objects called that function. Iāve gotten into the habit of adding that to every Lineā¦ Iām constantly getting ābugsā from multiple copies of a script running I never realized. You can Create a utility function in a C# script like this:
using UnityEngine;
using System.Collections;
public static class Utility
{
public static void MyDebug(GameObject obj, string txt)
{
Debug.Log(obj.GetInstanceID().ToString() + ": " + txt);
}
}
// Call it like this
Utility.MyDebug(gameObject,"Message");