hi there!
it is the first time, that i post a question here. i am just starting to work with c#.
here is my problem:
i have a scene with different objects (pins) in it and i want to get the object name by touching them.
therefore i am using the raycast function. i did two different versions in one file so tat it can be used on pc/mac and on ios/android.
the script part of the pc version works just fine but on android nothing happens.
here is the code:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class PinsSelection : MonoBehaviour {
//public GameObject ShowDescriptionObject;
public GameObject DeactivatePins;
public string tagCheck = "Pins_Tag";
public Ray ray;
//public bool checkAllTags = false;
/*
public GameObject eventReceiverPins;
public bool startsChecked = true;
bool mChecked = true;
bool mStarted = false;
void Start ()
{
if (eventReceiver == null) eventReceiver = gameObject;
mChecked = !startsChecked;
mStarted = true;
Set(startsChecked);
}
*/
void Update ()
{
#if UNITY_ANDROID || UNITY_IPHONE
bool foundHit = false;
RaycastHit hit = new RaycastHit();
//ray = Camera.main.ScreenPointToRay(Input.mousePosition);
int i = 0;
while (i < Input.touchCount)
{
if (Input.GetTouch(i).phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
if (Physics.Raycast(ray, out hit))
{
audio.Play();
if (hit.transform.tag == tagCheck)
{
audio.Play(44100);
DeactivatePins.GetComponent<MenuOnOff>().HidePins();
}
}
}
++i;
}
#else
RaycastHit hit = new RaycastHit();
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Input.GetButton("Fire1"))
{
if (Physics.Raycast(ray, out hit))
{
audio.Play();
if (hit.transform.tag == tagCheck)
{
audio.Play(44100);
print(hit.collider.gameObject.name);
DeactivatePins.GetComponent<MenuOnOff>().HidePins();
}
}
}
#endif
}
}
the audio.Play() function is just for debugging. so i know which part of the code works and which does not.
on the mobile device, the sound is played when i touch the objects. so i know, that the raycast is perfectly executed.
the riddle is that the code afterwards is not executed at all, as it seems, allthoug this part is working perfectly on PC:
if (Physics.Raycast(ray, out hit))
{
audio.Play();
if (hit.transform.tag == tagCheck)
{
audio.Play(44100);
DeactivatePins.GetComponent<MenuOnOff>().HidePins();
}
}
the question is now, why does it work on pc but not on android?