当前位置:网站首页>Unity 实现简单画板画画功能(笔记)
Unity 实现简单画板画画功能(笔记)
2022-07-27 21:05:00 【X-q-X】
一、搭好场景
- 创建一个plan
- 摄像机调成正交摄像机
- 创建三个cube,附上材质
- 再创建一个cube,找个色板,
- 创建一个脚本,挂在非失活物体上
- 创建一个slider,放在旁边

二、写代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Draw : MonoBehaviour {
LineRenderer line;
Material mat;
public Slider slider;
int num = 0;//总共画画点数
Color c;
// Use this for initialization
void Start () {
slider.value = 0.1f;
}
// Update is called once per frame
void Update () {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray,out hit))
{
if (Input.GetMouseButtonDown(0))
{
if (c==null)
{
return;
}
GameObject obj = new GameObject();
line= obj.AddComponent<LineRenderer>();
line.material.color= c;
line.widthMultiplier = slider.value;//宽度
line.SetPosition(0,hit.point);
line.SetPosition(1, hit.point);
num = 0;
}
if (Input.GetMouseButton(0))
{
num++;
line.positionCount = num;
line.SetPosition(num - 1, hit.point+Vector3.up*0.2f);
}
if (Input.GetMouseButtonDown(1))
{
StartCoroutine(ChangeColor());
}
}
}
IEnumerator ChangeColor()
{
yield return new WaitForEndOfFrame();
Texture2D texture2D = new Texture2D(Screen.width,Screen.height,TextureFormat.RGB24,true);
texture2D.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
texture2D.Apply();
c = texture2D.GetPixel((int)Input.mousePosition.x, (int)Input.mousePosition.y);
}
}
三、效果
Unity 画板
边栏推荐
- [signal denoising] signal denoising based on Kalman filter with matlab code
- 详解分布式系统的幂等
- Find and leverage xxE – XML external entity injection
- My annual salary is 1million, and I don't have clothes more than 100 yuan all over my body: saving money is the top self-discipline
- TCP的粘包拆包问题+解决方案
- 真的很难理解?RecyclerView 缓存机制到底是几级缓存?
- Learn more about xxE injection
- Explain the idempotence of distributed system in detail
- 华为鸿蒙 3 正式发布,这个安全功能解决了一大痛点
- Common Taylor expansion
猜你喜欢

NDK series (6): let's talk about the way and time to register JNI functions

Introduction to several common usage scenarios of message queue

Starfish Os X MetaBell战略合作,元宇宙商业生态更进一步

Technical certification | Tupo software and Huawei cloud create a new situation of win-win cooperation

29. Learn the stacked column chart of highcharts using percentage

置信区间之正态

29.学习Highcharts 使用百分比的堆叠柱形图

华为鸿蒙 3 正式发布,这个安全功能解决了一大痛点

一位软件投资者的独白:我为什么不追逐快速增长的公司
![[elm classification] classification of UCI data sets based on nuclear limit learning machine and limit learning machine, with matlab code](/img/bd/fe105f0af3a24ad6f220fa35bb5e8d.png)
[elm classification] classification of UCI data sets based on nuclear limit learning machine and limit learning machine, with matlab code
随机推荐
Socket interaction process of four waves
[soft test software evaluator] 2014 comprehensive knowledge over the years
TCP的粘包拆包问题+解决方案
File & recursion 14.1
2019年全球十大半导体厂商:英特尔重回第一,苹果逆势大涨
基于原生js实现今日新闻网站
[signal denoising] signal denoising based on Kalman filter with matlab code
7.6万人停工!东芝宣布关闭日本所有工厂
The total investment is 60billion! Foxconn semiconductor high-end package test project officially settled in Qingdao
低代码开发前景如何,大家都真的看好低代码开发吗?
新技术引领大中型企业营销新变革,用友BIP CRM重磅发布!
JS array copy speed test 220320
After returning to mixlab for three days, "creative team" cured my spiritual internal friction
[image defogging] image defogging based on dark channel and non-mean filtering with matlab code
请求合并哪家强——接口请求合并的3种技巧,性能直接爆表
置信区间之正态
MySQL之数据查询(WHERE)
一位软件投资者的独白:我为什么不追逐快速增长的公司
org.junit.runners.model.InvalidTestClassError: Invalid test class ‘com.zhj.esdemo.MysqlTests‘: 1.
【CVA估值训练营】如何快速读懂上市公司年报——第四讲