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);
}
}
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
Tidak ada komentar:
Posting Komentar