Search Unity

Question Making of a InfoPanel for a AR Weather Application for mobile.

Discussion in 'AR/VR (XR) Discussion' started by vedantgirkar32, Jun 11, 2020.

  1. vedantgirkar32

    vedantgirkar32

    Joined:
    May 28, 2020
    Posts:
    10
    I'm trying to make an AR app for mobile which uses a house model to along with various assets like rain, snow, etc prefabs to portray the current weather. I need to make a panel along the side of the model to show details like the temperature, humidity, and precipitation index. This panel is not a part of the UI but the part of the 3D AR Model. So I need to be able to change the content of this panel every day. I make a prefab of a 3D - Object -> TextMeshPro and I tried to change its text by creating a cube and a sphere below it and when you tap on it, it should change the text of the prefab to either 1 or 2 respectively just for experimentation purposes. but it stayed strong to what it was by default.
    I have included my code below:



    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6.  
    7. public class Place : MonoBehaviour
    8. {
    9.  
    10.     public Transform SpawnLoc;
    11.     public GameObject SpawnObject;
    12.    
    13.  
    14.     // Start is called before the first frame update
    15.     void Start()
    16.     {
    17.        
    18.     }
    19.  
    20.     // Update is called once per frame
    21.     void Update()
    22.     {
    23.         if(Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Began)
    24.         {
    25.             RaycastHit hit;
    26.             Ray ray = Camera.main.ScreenPointToRay(Input.touches[0].position);
    27.  
    28.             if(Physics.Raycast(ray, out hit, 100.0f))
    29.             {
    30.                 if(hit.collider.name == "Cube")
    31.                 {
    32.                     Text TextObj = GameObject.Find("SpawnObject").GetComponent<Text>();
    33.                     TextObj.text = "1";
    34.                     Instantiate(SpawnObject, SpawnLoc.position, SpawnLoc.rotation);
    35.                    
    36.                    
    37.                 }
    38.             }
    39.         }
    40.     }
    41. }
    42.  
    The SpawnObject is the prefab of the TextMeshPro.


    Does anybody have any ideas about how to fix this?

    Thank You.