У меня есть следующий код:
void Update ()
{
if (Application.platform == RuntimePlatform.Android)
{
if(!already_switched){
try
{
// Create new NFC Android object
AndroidJavaObject mActivity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity"); // Activities open apps
mIntent = mActivity.Call<AndroidJavaObject>("getIntent");
string sAction = mIntent.Call<String>("getAction"); // resulte are returned in the Intent object
if (sAction == "android.nfc.action.NDEF_DISCOVERED")
{
Debug.Log("Tag of type NDEF");
}
else if (sAction == "android.nfc.action.TECH_DISCOVERED")
{
GetComponent<ButtonScrollingUp>().actual_pos = GetComponent<ButtonScrollingUp>().actual_pos + 1;
if (GetComponent<ButtonScrollingUp>().actual_pos > GetComponent<ButtonScrollingUp>().images.Count) GetComponent<ButtonScrollingUp>().actual_pos = 0;
image.GetComponent<SpriteRenderer>().sprite = GetComponent<ButtonScrollingUp>().images[GetComponent<ButtonScrollingUp>().actual_pos];
text_.GetComponent<Text>().text = GetComponent<ButtonScrollingUp>().texts[GetComponent<ButtonScrollingUp>().actual_pos];
return;
}
else if (sAction == "android.nfc.action.TAG_DISCOVERED")
{
tag_output_text.text += "Not supported";
}
else
{
tag_output_text.text = "Scan a NFC tag to make the cube disappear...";
return;
}
}
catch (Exception ex)
{
string text = ex.Message;
tag_output_text.text = text;
}
}
}
}
Код изменяет изображение, когда NFC приближается к телефону, проблема в том, что он меняет изображение один раз за кадр. Я мог бы сделать это только для того, чтобы измениться один раз, но я не хочу этого, я хочу, чтобы каждый раз, когда кто-то приближался к NFC, он менялся. Я думаю, что я мог бы решить это, если бы я очистил стек намерений, и я могу сделать это с помощью:
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Но я не знаю, как это сделать в c # и в единстве.
Может ли кто-нибудь мне помочь?