Start a new topic

How to reference instantiated (Clone) in Script

I'm trying to access the rotation of my Drawable that I have attached to a tracked cylinder. I want to then use this rotation variable across other scripts. I would also be open to using the rotation of the tracked cylinder instead of the model attached as the drawable since they are bounded together and essentially will have the same rotation. 


My drawable is a prefab with a obj. and a script attached. Inside the script I set a public variable to the object's rotation. 


The issue I'm running into is when I try and reference this object and grab that rotation variable from another script, I'm pointing to the generic prefab and not the active instantiated clone that is generated when the target is recognized. 


For now I'm just trying to grab this variable and display it as text.


Any help with this would be amazing! Thanks


Wikitude Version 9.10.0

Unity Version 2021.3.2


Script Attached to Drawable:


public class GetCylinderData : MonoBehaviour
{
    
    public float canRoatationRaw;

    void Update()
    {
        canRoatationRaw = this.transform.rotation.eulerAngles.y;
        Debug.Log(canRoatationRaw);
    }

}

  

Script trying to display rotation as text:


 

public class UpdateRotationText : MonoBehaviour
{

    GetCylinderData getCylinderData;
    [SerializeField] GameObject cylinder;

    private string rotationString; 

    void Awake()
    {
        getCylinderData = cylinder.GetComponent<GetCylinderData>();
    }

    void Update()
    {
        rotationString = getCylinderData.canRoatationRaw.ToString();
        this.GetComponent<Text>().text = rotationString;
    }
}
 

 



1 Comment

Hi Felid,

what are you assigning to the cylinder field? Are you assigning a prefab or the drawable from the scene?


Kind regards,
Gökhan

Login or Signup to post a comment