想要在渲染纹理相机unity3d上获得屏幕点

时间:2017-10-06 13:06:25

标签: unity3d unity5

我正在制作狙击游戏,我有2个摄像头,一个渲染整个环境,第二个是枪的范围,具有高变焦质量。 我可以通过主摄像头在屏幕上显示敌人点。并且在主摄像机上显示正确,但在示波器摄像机(第2摄像机)中,显示不正确。我想展示这些与敌人完全相同的点。 这是我的脚本到目前为止显示点。我正在附加屏幕截图,第一个用于示波器相机并且没有显示正确的位置,第二个用于主相机,显示在适当的位置(红色圆圈指向)Red circle is pointing

using UnityEngine;
using UnityEngine.UI;

public class identity_shower : MonoBehaviour {
    public Texture tex;
    public GameObject helt;
    public bool target_is_high =false;
    private int counter_for_high = -1;
    private int counter_for_low  = -1;
    private int counter_value = 50;
    private bool bool_for_high = false;
    private bool bool_for_low = false;
    private Camera scope_cam_active;
    private RectTransform rectTransform;
    private Vector2 uiOFFset;



    // Update is called once per frame

    void OnGUI()
    {
        GameObject[] objs = GameObject.FindGameObjectsWithTag("enemy_soldier");
        if( objs.Length<=0 )
        {
             return;
        }
        if (bool_for_high) 
        {
             Vector2 pos_to_display = Camera.main.WorldToScreenPoint (this.transform.position);
             GUI.DrawTexture (new Rect(pos_to_display.x-10.0f,(Screen.height- pos_to_display.y)-40.0f,15,15),tex);
        }
    }

    public void show_your_identity()
    {
        if (target_is_high) {
            if (counter_for_high >= counter_value) 
            {
                 return;
            }
            counter_for_high = counter_for_high + 1;
            if (counter_for_high >= counter_value) 
            {
                 bool_for_high = true;      
             }
        } else if(!target_is_high)
        {
             if (counter_for_low >= counter_value) 
             {
                return;
             }
             counter_for_low = counter_for_low + 1;
             if (counter_for_low >= counter_value) 
             {
                 bool_for_low = true;
             }
        }
     }
}

0 个答案:

没有答案