Home Game Development unity – On display enemy indicating arrow

unity – On display enemy indicating arrow

0
unity – On display enemy indicating arrow

[ad_1]

I’m engaged on indicating on display arrow to level in the direction of the enemy. I’ve a atmosphere which encompass a participant and three enemy positioned at totally different place on the atmosphere.I want an arrow indicating the enemy,in order that the participant can transfer in the direction of the enemy within the atmosphere.

How can I do that?Can anyone please assist me out.

I’ve bought a script on looking.

public Texture2D icon; //The icon. Preferably an arrow pointing upwards.
public float iconSize = 50f;
[HideInInspector]
public GUIStyle gooey; //GUIStyle to make the field across the icon invisible. Public in order that all the things has the default stats.
Vector2 indRange;
float scaleRes = Screen.width / 500; //The width of the display divided by 500. Will make the GUI robotically
//scale with various resolutions.
Camera cam;
bool seen = false; //Whether or not the thing is seen within the digital camera.

void Start () {
    seen = GetComponent<SpriteRenderer> ().isVisible;

    cam = Camera.foremost; //Don't use Camera.foremost in a looping methodology, its very gradual, as Camera.foremost really
    //does a GameObject.Find for an object tagged with ForemostCamera.

    indRange.x = Screen.width - (Screen.width / 6);
    indRange.y = Screen.top - (Screen.top / 7);
    indRange /= 2f;

    gooey.regular.textColor = new Vector4 (0, 0, 0, 0); //Makes the field across the icon invisible.
    seen=false;
}

void OnGUI () {
    if (seen) {
        Vector3 dir = rework.place - cam.rework.place;
        dir = Vector3.Normalize (dir);
        dir.y *= -1f;

        Vector2 indPos = new Vector2 (indRange.x * dir.x, indRange.y * dir.y);
        indPos = new Vector2 ((Screen.width / 2) + indPos.x,
            (Screen.top / 2) + indPos.y);

        Vector3 pdir = rework.place - cam.ScreenToWorldPoint(new Vector3(indPos.x, indPos.y,
            rework.place.z));
        pdir = Vector3.Normalize(pdir);

        float angle = Mathf.Atan2(pdir.x, pdir.y) * Mathf.Rad2Deg;

        GUIUtility.RotateAroundPivot(angle, indPos); //Rotates the GUI. Only rotates GUI drawn after the rotate is known as, not earlier than.
        GUI.Box (new Rect (indPos.x, indPos.y, scaleRes * iconSize, scaleRes * iconSize), icon,gooey);
        GUIUtility.RotateAroundPivot(0, indPos); //Rotates GUI again to the default in order that GUI drawn after is just not rotated.
    }
}

void OnBecameInvisible() {
    seen = false;
}
//Turns off the indicator if object is onscreen.
void OnBecameVisible() {
    seen = true;
}

}

The drawback is begin once I play the scene the arrow is seen firstly however its get invisible quickly

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here