The scoreboard doesn't stick to the anchor point
Opened this issue · 1 comments
Whenever I move my phone the scoreboard moves as well, it doesn't stick to the anchor point. I think, the position of the scoreboard is not getting updated to the position of the anchor point. May I know why is this happening?
Here is my Update() function
void Update()
{
// The session status must be Tracking in order to access the Frame.
if (Session.Status != SessionStatus.Tracking)
{
return;
}
// If there is no plane, then return
if (detectedPlane == null)
{
return;
}
// Check for the plane being subsumed.
// If the plane has been subsumed switch attachment to the subsuming plane.
while (detectedPlane.SubsumedBy != null)
{
detectedPlane = detectedPlane.SubsumedBy;
}
// Make the scoreboard face the viewer
transform.LookAt(firstPersonCamera.transform);
// Move the position to stay consistent with the plane
transform.position = new Vector3(transform.position.x,
detectedPlane.CenterPose.position.y + yOffset,
transform.position.z);
}
I am also including my CreateAnchor() function
private void CreateAnchor()
{
// Create the position of the anchor by raycasting a point towards the top of the screen.
Vector2 pos = new Vector2(Screen.width * .5f, Screen.height * .90f);
Ray ray = firstPersonCamera.ScreenPointToRay(pos);
Vector3 anchorPosition = ray.GetPoint(5f);
// Create the anchor at that point.
if (anchor != null)
{
DestroyObject(anchor);
}
anchor = detectedPlane.CreateAnchor(new Pose(anchorPosition, Quaternion.identity));
// Attach the scoreboard to the anchor.
transform.position = anchorPosition;
transform.SetParent(anchor.transform);
// Record the y offset from the plane.
yOffset = transform.position.y - detectedPlane.CenterPose.position.y;
// Finally, enable the renderers.
foreach (Renderer r in GetComponentsInChildren<Renderer>())
{
r.enabled = true;
}
}
Same. I got this error from logcat
05-19 15:29:20.409 2841 2860 E Unity : NullReferenceException: Object reference not set to an instance of an object
05-19 15:29:20.409 2841 2860 E Unity : at SceneController.SetSelectedPlane (GoogleARCore.DetectedPlane selectedPlane) [0x00023] in B:\Unity\Test\Test2\Assets\SceneController.cs:34
05-19 15:29:20.409 2841 2860 E Unity : at SceneController.ProcessTouches () [0x00064] in B:\Unity\Test\Test2\Assets\SceneController.cs:27
05-19 15:29:20.409 2841 2860 E Unity : at SceneController.Update () [0x00023] in B:\Unity\Test\Test2\Assets\SceneController.cs:69