【发布时间】:2019-11-12 07:51:40
【问题描述】:
我是统一的初学者,我想在球体对象上放置一个标记到特定位置(按纬度和经度)。我试过这段代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class testPosLatLong : MonoBehaviour {
public float longi;
public float lati;
public float radius;
public Transform marker;
// Use this for initialization
void Start () {
// longitude and latitude of uae
longi=23.4241f;
lati=53.8478f;
// Transfer to Radians from Degrees
float templongi = longi * Mathf.PI / 180;
float templati = lati * Mathf.PI / 180;
float Xpos = radius * Mathf.Cos(templati) * Mathf.Cos(templongi);
float Ypos = radius * Mathf.Cos(templati) * Mathf.Sin(templongi);
float Zpos = radius * Mathf.Sin(templati);
Debug.Log ("X, Y, Z" + Xpos + " " + Ypos + " " + Zpos);
// Set the X,Y,Z pos from the long and lat
Instantiate(marker);
marker.position = new Vector3 (Xpos, Zpos, Ypos);
Debug.Log ("Marked positions: X, Y, Z" + Xpos + " " + Ypos + " " + Zpos);
}
// Update is called once per frame
void Update () {
}
}
我需要将这个脚本拖到我的球体对象或相机对象吗?或创建任何其他对象并在其上拖动。因为我是 Unity 的初学者,所以我不知道如何在球体上添加标记。
我的球体是一个球体(我在球体中添加了材质(添加了地球图像)并将其制作为球体对象,如屏幕截图所示)。 将上述脚本添加到相机对象后,当我播放并检查控制台时,x、y、z 位置为 0,并且在地球上看不到任何标记
我想在相应的国家/地区添加大头针并标记它。类似于地球上的http://kitsdmcc.com/news
【问题讨论】:
-
您实例化了球体,但移动了预制件而不是您制作的预制件。你需要做类似 var newmarker = Instantiate(marker) 然后 newmarker.position = ...
-
还有我应该在哪里附加到相机对象或球体对象的c#脚本,你有示例代码吗,我只是这个统一的初学者。
-
那是代码
-
@BugFinder 你能帮忙把这个预制件添加到球体吗,我试过你说的,但看不到球体上的物体
-
使用场景来调试它的第一个位置..检查它的放置位置