当前位置:网站首页>Unity implements simple Sketchpad drawing function (notes)
Unity implements simple Sketchpad drawing function (notes)
2022-07-27 23:55:00 【X-q-X】
List of articles
One 、 Set up the scene
- Create a plan
- Turn the camera into an orthogonal camera
- Create three cube, Attach material
- Create another cube, Find a palette ,
- Create a script , Hang on a non inactivated object
- Create a slider, Put it aside

Two 、 Write code
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;// Total painting points
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;// Width
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);
}
}
3、 ... and 、 effect
Unity Drawing board
边栏推荐
- Reinforcement learning - pytorch realizes advantage actor critical (A2C)
- BUUCTF-RSA
- 如果我们是那晚负责修复 B 站崩了的开发人员
- Arm32 for remote debugging
- Nail alarm tool
- Accelerate IGBT localization! BYD semiconductor will be listed independently, with a market value of 30billion yuan!
- 【JS 逆向百例】某公共资源交易网,公告 URL 参数逆向分析
- 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
- Sort sort
- Explain the idempotence of distributed system in detail
猜你喜欢
随机推荐
Use a grayscale filter
[RoarCTF2019]babyRSA威尔逊定理
Latex常用总结(2):输入矩阵(输入矩阵、对角阵、方程组等)
资深如何确定软件测试结束的标准
Sort sort
解密 OOM 崩溃下降 90% 的秘密~
UE4 official AEC blueprint case course learning notes
CPU的控制方式
Realization of gobang man-machine combat
【开发教程9】疯壳·开源蓝牙心率防水运动手环-心率监测
Current situation and future of Nb IOT industry: cross the threshold of 100million shipments and rush to 5g connection!
Accelerate IGBT localization! BYD semiconductor will be listed independently, with a market value of 30billion yuan!
为什么 Redis 集群要使用反向代理? 看这篇就明白了
BUUCTF-RSA roll
消息队列常见的几种使用场景介绍
Ideas, methods and steps of making folding fans with 3DMAX
C # delegate usage -- console project, which implements events through delegation
File & recursion 14.1
(十二)51单片机----用DS18B20浅测一下工(江)西的室外温度
Your list is too laggy? These four optimizations can make your list silky smooth









