c# - 更新功能在 AR 应用程序中不起作用
问题描述
我正在开发显示附近 POI 的 AR 应用程序。正如您在下面的屏幕截图中看到的那样,ArAlignedMap 有一个脚本,允许我们使用真实世界坐标创建 POI。[WorldScaleAr][1]
我分配的 POI 标记预制件之一是 POI45。POI45 在下面的屏幕截图中有对象。[POI45][2]
我为 LabelIcon 编写了一个脚本。该脚本如下;
脚本运行后,POI 的颜色会发生变化,但不会在每一帧中都发生变化。为什么它不更新 POI 的颜色?
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using static System.Math;
using Mapbox.Examples; // example script import
public class gradient45 : MonoBehaviour
{
Vector3 temp;
float temp2;
float distances;
int z = 2;
float gra = 0;
double r = 6371000;
double[,] coords = new double[,] { { 39.872446, 32.735564 } }; // Eğitim Fakültesi
double lat1;
double lat2;
double lon1;
double lon2;
double user_lat;
double user_lat_rad;
double user_lon;
double user_lon_rad;
String x;
String y;
// Start is called before the first frame update
void Start()
{
// get poi Location
lat1 = Math.PI * coords[0, 0] / 180.0;
// lat2 = Math.PI * user[0, 0] / 180.0;
lon1 = Math.PI * coords[0, 1] / 180.0;
// lon2 = Math.PI * user[0, 1] / 180.0;
}
// Update is called once per frame
void Update()
{
// Get user location
// Latitude
x = getLocation.x1.ToString();
user_lat = Convert.ToDouble(x);
user_lat_rad = Math.PI * user_lat / 180.0; // Radian
// Longitude
y = getLocation.y1.ToString();
user_lon = Convert.ToDouble(y);
user_lon_rad = Math.PI * user_lon / 180.0; // Radian
// Change POIs sizes
distances = Convert.ToSingle(distance(user_lat_rad, user_lon_rad));
temp2 = gra;
temp2 = temp2 + 100f;
gra = temp2;
GetComponent<Renderer>().material.color = new Color((gra/255f), 161f/255f, 127f/255f);
}
public double distance(double lat2, double lon2)
{
// Haversine Formula
// Lat2,Lon2 = User Location
// Lat1,Lon1 = POI Location
double dist1 = Sqrt((Pow(Sin((lat2 - lat1) / 2), 2)) + Cos(lat2) * Cos(lat2) * (Pow(Sin((lon2 - lon1) / 2), 2)));
double distance = 2 * r * Asin(dist1);
return distance;
}
} ```
[1]: https://i.stack.imgur.com/ONcxC.jpg
[2]: https://i.stack.imgur.com/Fh9q2.jpg
解决方案
推荐阅读
- haskell - “Either String”是否有任何新类型?
- c++ - 模板规范获取“对重载函数的模糊调用”
- javascript - 无法在 MUI 搜索栏中写入
- postgresql - 如何将 Postgres 驱动程序添加到 Open Liberty?
- vue.js - (Vue.js) 在计算中,我不能使用数据
- r - 使用 github_document 输出显示来自 RMarkdown 的数字
- xml - 如何在 CFML 中解析 XML 数据
- firebase - 是否有任何 API 或 firebase 命令来获取 Firebase App Distribution 中 iOS 设备的 UUID 列表
- python-3.x - 如何将字典写入 CSV 文件?
- node.js - 2021 年使用 Nodejs + TypeScript 的 REST API