Hey Guys
I am very annoyed because I have searched the Internet for days.
I want to load a png file from my Resources folder called lightSign, store it in the Texture2D Variable texture and draw it in the OnGUI method, but it dont works because its an empty texture, when I run the game as I see in the Inspector, butthe Bebug log is not schowing any error even when the method gets called.
its so strange.
any ideas?
using UnityEngine;
using System.Collections;
public class camdetection : MonoBehaviour {
private int GUIdisplay;
//varialbles for GUI
public Texture2D texture;
public float angle = 0;
public Vector2 size = new Vector2(128, 128);
Vector2 pos = new Vector2(0, 0);
Rect rect;
Vector2 pivot;
Vector3 direction;
Vector2 zweidirection;
Vector2 camdirection;
// Use this for initialization
void Start () {
//Resources.Load ("Feindpräsenz anzeige transparent-1.png");
//GUI
texture = Resources.Load("lightSign.png",typeof(Texture2D)) as Texture2D;
heightMultiplier=0.1f;
Arme = GameObject.FindGameObjectWithTag("Arme");
Cam = GameObject.FindGameObjectWithTag("MainCamera");
}
void UpdateSettings() {
pos = new Vector2 (Screen.width / 2 + 150, Screen.height / 2 - 40);
rect = new Rect (pos.x - size.x * 0.5f, pos.y - size.y * 0.5f, size.x, size.y);
pivot = new Vector2 (Screen.width / 2, Screen.height / 2);
direction = new Vector3 ((transform.position.x - Arme.transform.position.x), transform.position.y - Arme.transform.position.y, transform.position.z - Arme.transform.position.z);
zweidirection = new Vector2 (direction.x, direction.z);
camdirection = new Vector2 (Cam.GetComponent<Camera> ().transform.forward.x, Cam.GetComponent<Camera> ().transform.forward.z);
angle = Vector2.Angle (camdirection, zweidirection);
Vector3 cross = Vector3.Cross(camdirection, zweidirection);
if (cross.z > 0)
angle = 360 - angle;
GUIdisplay -= 1;
}
void OnGUI ()
{
if (Application.isEditor) {
UpdateSettings ();
}
if (GUIdisplay > 0) {
Matrix4x4 matrixBackup = GUI.matrix;
GUIUtility.RotateAroundPivot (angle - 90.0f, pivot);
GUI.DrawTexture (rect, texture);
GUI.matrix = matrixBackup;
}
}
}