2

I have a problem, I have a 3D animation and I added two collidersenter image description here

I did this because I want to detect when the user touch the head, the chest or the abs zone. And as the picture shows, in the chestUpper zone I add a sphere collider, in the hip and head too. I have colliders and I have this script

public class OnTouch : MonoBehaviour 
{
    public int cuerpo = 2;

    void Update () 
    {
        if (!Input.GetMouseButtonDown(0)) return;

        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;
        Debug.Log("entre");

        if (!Physics.Raycast(ray,out hit)) return;

        Debug.Log("entre2");
        Debug.Log(hit.collider.name);

        if (hit.collider.name == "head") { }
        else if (hit.collider.name == "chestUpper") { }
        else if (hit.collider.name == "abdomenUpper") { }
        else if (hit.collider.name == "hip") { }    
    }
}

The problem is that sometimes I detect the mouse when I run it in unity, SOMETIMES.. And when I build and run the project to my cellphone, always detect the head, but the others colliders are not detected. How can resolve this?

AustinWBryan
  • 3,249
  • 3
  • 24
  • 42
  • With it detects always the head, you mean if you press another part of the body it appears as you press the head anyway? – Ignacio Alorre May 21 '18 at 08:51
  • mm no when i run it on unity, everything works fine, the problem it's when i run it on my phone, only detects the collider of the head, the others don't, but the collider of the collider is detected only when touch the head(that means is fine – Oscar.Aldaz May 21 '18 at 13:34
  • Do you have big collider attached to the parent model? Maybe that collider is blocking the raycast. Can you add `else` at the end of the `else if` and see if something else is being hit? – Programmer May 21 '18 at 19:19
  • Hi, mm i download the object from assets store, and i think so, have a rigibody, but if that would be a problem, i couldn't detected either views(unity in laptop and phone) – Oscar.Aldaz May 21 '18 at 19:28
  • Never mind, It was my phone, I ran it iin other phone i everything works fine, sorry and thanks for the answers jaja :D – Oscar.Aldaz May 22 '18 at 01:04
  • But if anyone knows a great tutorial to make and android plugin to send and intent from a Java app to unity, tell me please – Oscar.Aldaz May 22 '18 at 01:07

0 Answers0