划线标注

 

 

手动摆放线段和标识太累,写个脚本做。如有问题,请加公众号 :哎呦还不错喔                    

 void Start()
    {
        Vector3 Tpos = transform.position;
        int w , h ;

        w = Camera.main.WorldToScreenPoint(Tpos).x < Screen.width / 2 ? -1 : 1;
        h = Camera.main.WorldToScreenPoint(Tpos).y < Screen.height / 2 ? -1 : 1;


        GameObject xian = new GameObject();
        LineRenderer Line = xian.AddComponent<LineRenderer>();
        Line.SetWidth(0.1f, 0.1f);
        Line.SetVertexCount(3);
        Line.SetPosition(0, Tpos);
        Line.SetPosition(1, Tpos + new Vector3(2*w, 2*h, 0));
        Line.SetPosition(2, Tpos + new Vector3(3*w, 2*h, 0));

        Transform tr = (Instantiate(GameObject.Find("Button")) as GameObject).transform;
        tr.parent = GameObject.Find("Canvas").transform;
        tr.position = Tpos + new Vector3((3+0.5f)*w, 2*h, 0);
        tr.GetComponentInChildren<Text>().text=transform.name;
    }
  

 

posted @ 2017-05-25 10:40  哎呦不能错喔  阅读(174)  评论(0编辑  收藏  举报