Creating Compass In Unity 3D - 2

Advertisemen



It is very handy way to build the navigation system where player have to refer to map in the larger field. This video will show you guys, how to build compass to detect the movements of the player in scene.

If you guys like to use the images used in this tutorial, drag and drop the images from below :


If you guys like to copy and paste the code used in the video above, here is the C# code :

using UnityEngine;
using System.Collections;

public class com : MonoBehaviour {
    public Transform player;
    public Texture compBg;
    public Texture blipTex;

    void OnGUI(){
        GUI.DrawTexture(new Rect(0, 0, 120, 120), compBg);
        GUI.DrawTexture(CreateBlip(), blipTex);
    }

    Rect CreateBlip(){
        float angDeg = player.eulerAngles.y - 90;
        float angRed = angDeg * Mathf.Deg2Rad;

        float blipX = 25 * Mathf.Cos(angRed);
        float blipY = 25 * Mathf.Sin(angRed);

        blipX += 55;
        blipY += 55;

        return new Rect(blipX, blipY, 10, 10);
    }
}

Advertisemen

Disclaimer: Gambar, artikel ataupun video yang ada di web ini terkadang berasal dari berbagai sumber media lain. Hak Cipta sepenuhnya dipegang oleh sumber tersebut. Jika ada masalah terkait hal ini, Anda dapat menghubungi kami disini.

Tidak ada komentar:

Posting Komentar

© Copyright 2017 Tutorial Unity 3D