0
votes

Hello so I've been looking for a solution for my problem but looks like there is absolutely nothing about it.

I'm working on a scene where I have some 3D object renderred on a ground plane and my goal is making an animation on that 3D object start by tapping it. I'm using latest version of vuforia 10.4 with Unity 2020.3.9f1. I have a script for instantiating the 3d Model and making the plane finder disappear as long as it doesn't lose tracking.`using System.Collections; using System.Collections.Generic; using UnityEngine;

public class sceneManager : MonoBehaviour { private string level = "snake";

public GameObject[] renderredPrefab;
public GameObject ground;
public GameObject groundFinder;

private int levelChecker(string levelName)
{
    if (levelName == "snake")
        return 0;

    else return 1;
}

public void spawnObject(int i)
{
    Instantiate(renderredPrefab[levelChecker(level)], new Vector3(0, 0, 0), Quaternion.identity, ground.transform);
}

public void groundFinderOff()
{
    groundFinder.SetActive(false);
}

public void groundFinderOn()
{
    groundFinder.SetActive(true);
}

} And another one to trigger the animation following the game object's tag hereusing System.Collections; using System.Collections.Generic; using UnityEngine;

public class animationTriggerManager : MonoBehaviour { private Animator m_Animator;

private string objectName;
private GameObject[] eos;
private GameObject snake;

[SerializeField]
private Camera ARCamera;

// Start is called before the first frame update
void Start()
{
    // Get the different eos present on the scene
    for (int i = 0; i < eos.Length; i++)
    {
        eos[i] = GameObject.FindWithTag("myEolienne" + i);
    }

    // Get snake game objecct in the scene
    snake = GameObject.FindWithTag("Snake");
}

// Update is called once per frame
void Update()
{
    if (Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Began)
    {
        Ray ray = ARCamera.ScreenPointToRay(Input.GetTouch(0).position);

        if (Physics.Raycast(ray, out RaycastHit hit))
        {
            objectName = hit.collider.name;
            Debug.Log("raycast touched " + hit.transform.name);
            switch (objectName) //Get the Animator depending on which gameObject been tapped on.
            {
                case "myEolienne1":
                    m_Animator = eos[0].GetComponent<Animator>();
                    // Launch the animation on the gameObject that's been tapped 
                    m_Animator.SetTrigger("Helice_Rotate");
                    Debug.Log("rotate launched");
                    break;

                case "myEolienne2":
                    m_Animator = eos[1].GetComponent<Animator>();
                    // Launch the animation on the gameObject that's been tapped 
                    m_Animator.SetTrigger("Helice_Rotate");
                    Debug.Log("rotate launched");
                    break;

                case "myEolienne3":
                    m_Animator = eos[2].GetComponent<Animator>();
                    // Launch the animation on the gameObject that's been tapped 
                    m_Animator.SetTrigger("Helice_Rotate");
                    Debug.Log("rotate launched");
                    break;
                case "Snake":
                    m_Animator = snake.GetComponent<Animator>();
                    m_Animator.SetTrigger("snakeMoving");
                    break;
            }
        }
    }
}

} `

Note that each 3D model has different parts grouped in one parent that has a mesh collider on the parent only.enter image description here

The rendering works perfectly but I can't figure out what's wrong with my raycasting script. Note that I first tried with 3D model on image target and it worked fine.

Thanks in advance !