2017-11-16 1 views
0

북쪽으로지도를 회전하고 싶지만 회전을 계속하고 북쪽으로 멈추지 않습니다. 지도의 회전이 북쪽에 고정되어있는 Google지도처럼 출력물을 원합니다. 제 Update() 방법을 확인하십시오. 여기에 비디오를 확인하십시오 https://www.youtube.com/watch?v=liXmxdI3Adg&feature=youtu.begameobject를 북쪽으로 회전하십시오.

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 
using UnityEngine.UI; 
using System; 

public class GoogleAPI : MonoBehaviour { 
    private string url; 
    public RawImage img; 
    public float latitude; 
    public float longitude; 
    public Text text; 
    public Text northtext; 

    private IEnumerator Map(float lat, float lon){ 

     url = "https://maps.googleapis.com/maps/api/staticmap?key=AIzaSyAG0hDd5mZNla3GFCi0cs9wWTkWu-eBBWA&center="+lat+","+lon+"&zoom=19&format=png&maptype=roadmap&style=element:geometry%7Ccolor:0x1d2c4d&style=element:labels.text.fill%7Ccolor:0x8ec3b9&style=element:labels.text.stroke%7Ccolor:0x1a3646&style=feature:administrative.country%7Celement:geometry.stroke%7Ccolor:0x4b6878&style=feature:administrative.land_parcel%7Celement:labels.text.fill%7Ccolor:0x64779e&style=feature:administrative.province%7Celement:geometry.stroke%7Ccolor:0x4b6878&style=feature:landscape.man_made%7Celement:geometry.stroke%7Ccolor:0x334e87&style=feature:landscape.natural%7Celement:geometry%7Ccolor:0x023e58&style=feature:poi%7Celement:geometry%7Ccolor:0x283d6a&style=feature:poi%7Celement:labels.text%7Cvisibility:off&style=feature:poi%7Celement:labels.text.fill%7Ccolor:0x6f9ba5&style=feature:poi%7Celement:labels.text.stroke%7Ccolor:0x1d2c4d&style=feature:poi.business%7Cvisibility:off&style=feature:poi.park%7Celement:geometry.fill%7Ccolor:0x023e58&style=feature:poi.park%7Celement:labels.text.fill%7Ccolor:0x3C7680&style=feature:road%7Celement:geometry%7Ccolor:0x304a7d&style=feature:road%7Celement:labels.icon%7Cvisibility:off&style=feature:road%7Celement:labels.text.fill%7Ccolor:0x98a5be&style=feature:road%7Celement:labels.text.stroke%7Ccolor:0x1d2c4d&style=feature:road.highway%7Celement:geometry%7Ccolor:0x2c6675&style=feature:road.highway%7Celement:geometry.stroke%7Ccolor:0x255763&style=feature:road.highway%7Celement:labels.text.fill%7Ccolor:0xb0d5ce&style=feature:road.highway%7Celement:labels.text.stroke%7Ccolor:0x023e58&style=feature:transit%7Cvisibility:off&style=feature:transit%7Celement:labels.text.fill%7Ccolor:0x98a5be&style=feature:transit%7Celement:labels.text.stroke%7Ccolor:0x1d2c4d&style=feature:transit.line%7Celement:geometry.fill%7Ccolor:0x283d6a&style=feature:transit.station%7Celement:geometry%7Ccolor:0x3a4762&style=feature:water%7Celement:geometry%7Ccolor:0x0e1626&style=feature:water%7Celement:labels.text.fill%7Ccolor:0x4e6d70&size=360x640&scale=2"; 
     WWW www = new WWW (url); 
     yield return www; 
     img.texture = www.texture; 
     img.SetNativeSize(); 
    } 

    private IEnumerator StartLocationService(){ 
     if (!Input.location.isEnabledByUser) { 
      Debug.Log ("enable gps pls"); 
      yield break; 
     } 

     Input.location.Start(); 

     int maxWait = 20; 
     while(Input.location.status == LocationServiceStatus.Initializing && maxWait > 0){ 
      yield return new WaitForSeconds (1); 
      maxWait--; 
     } 

     if(maxWait <=0){ 
      Debug.Log ("Expired"); 
      yield break; 
     } 

     if (Input.location.status == LocationServiceStatus.Failed) { 
      Debug.Log ("Unable to determine device location"); 
      yield break; 
     } 



     latitude = Input.location.lastData.latitude; 
     longitude = Input.location.lastData.longitude; 

     yield break; 
    } 
    // Use this for initialization 
    void Start() { 
     img = img.GetComponent<RawImage>(); 
     StartCoroutine (StartLocationService()); 
     StartCoroutine (LoadData()); 
     Input.gyro.enabled = true; 
     Input.compass.enabled = true; 
    } 

    private IEnumerator LoadData(){ 
     while(true){ 
      latitude = Input.location.lastData.latitude; 
      longitude = Input.location.lastData.longitude; 
      text.GetComponent<Text>().text = "Lat: "+latitude+"\nLon: "+longitude; 
      StartCoroutine (Map(latitude, longitude)); 
      yield return new WaitForSeconds(1); 
     } 
    } 

    void Update(){ 
     img.GetComponent<RawImage>().transform.Rotate (0,0,Convert.ToInt16(Input.compass.trueHeading)); 
     northtext.GetComponent<Text>().text = Convert.ToInt16(Input.compass.trueHeading).ToString(); 
    } 
} 

답변

0

을 대신 회전을 설정하는 무한 회전된다.

void Update() 
{ 
    var targetEuler = new Vector3(0,0,Input.compass.trueHeading); 
    img.transform.rotation = Quaternion.Lerp(image.transform.rotation, targetEuler, Time.deltaTime); 
} 
:

당신이 뭔가를 할 수 있습니다

관련 문제