UGUI中点击鼠标绘制图片

来源:互联网 发布:两个淘宝店铺怎么关联 编辑:程序博客网 时间:2024/06/12 20:26

    Canvas canvas;
    public GameObject  image;
    void Start()
    {
        canvas = GameObject.Find("Canvas").GetComponent<Canvas>();
        image.GetComponent<Image>().enabled=false;
    }
    void Update(){      
        if(Input.GetMouseButtonDown(0)){
        image.GetComponent<Image>().enabled = true;
        Vector2 pos;
        if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, Input.mousePosition, canvas.worldCamera, out pos))
            {          
              image.GetComponent<RectTransform>().anchoredPosition = pos;
            }
        }       
    }

0 0
原创粉丝点击