当前位置:首页 » 《随便一记》 » 正文

关于unity用LineRenderer画图_一只学习的小鸟的博客

1 人参与  2021年12月22日 13:42  分类 : 《随便一记》  评论

点击全文阅读


一.学习的知识1.LineRenderer的用法 以及点击事件

二.画图代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class Draw : MonoBehaviour,IPointerDownHandler,IPointerUpHandler,IPointerExitHandler,IPointerEnterHandler
{
    LineRenderer line;
    bool fg = false;
    bool fgs = false;
    int inedex = 0;
    Vector3 vector;
    public void OnPointerDown(PointerEventData eventData)
    {
        line = new GameObject().AddComponent<LineRenderer>();
        line.material = new Material(Shader.Find("Sprites/Default"));
        fg = true;
        line.startColor = Color.red;
        line.endColor = Color.yellow;
        line.startWidth = 0.05f;
        line.endWidth = 0.05f;
    }
    public void OnPointerUp(PointerEventData eventData)
    {
        fg = false;
        inedex = 0;
        line = null;
    }
    // Start is called before the first frame update
    void Start()
    {
        
    }
    // Update is called once per frame
    void Update()
    {
        if(line!=null&&fg&&fgs)
        {
             vector= Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y,1));
            line.positionCount = inedex+1;
            line.SetPosition(inedex, vector);
            inedex++;
        }
    }
    public void OnPointerExit(PointerEventData eventData)
    {
        fgs = false;  
    }
    public void OnPointerEnter(PointerEventData eventData)
    {
        fgs = true;
    }
}


点击全文阅读


本文链接:http://zhangshiyu.com/post/31927.html

画图  用法  事件  
<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1