Source:

using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class AtwalPaint : MonoBehaviour {
public Material currentMaterial; private Color paintColor = Color.red;
private float paintSize = 0.1f;
private bool isPress = false;
private LineRenderer lineRenderer;
private List<Vector3> positions = new List<Vector3>();
private int lineCount = ; private void Update()
{
if (Input.GetMouseButtonDown())
{
isPress = true;
GameObject go = new GameObject("LineRenderer_" + lineCount);
go.transform.parent = gameObject.transform;
lineRenderer = go.AddComponent<LineRenderer>();
lineRenderer.startColor = paintColor;
lineRenderer.endColor = paintColor;
lineRenderer.startWidth = paintSize;
lineRenderer.endWidth = paintSize;
lineRenderer.material = currentMaterial;
lineRenderer.numCapVertices = ;
lineRenderer.numCornerVertices = ;
lineCount++;
AddPosition();
} if (isPress)
{
AddPosition();
} if (Input.GetMouseButtonUp())
{
lineRenderer = null;
positions.Clear();
isPress = false;
}
} void AddPosition()
{
Vector3 position = GetMousePoint();
if (positions.Count > )
{
if (Vector3.Distance(position, positions[positions.Count - ]) < 0.1f)
{
return;
}
}
position.z = -0.02f * lineCount;
positions.Add(position);
lineRenderer.positionCount = positions.Count;
lineRenderer.SetPositions(positions.ToArray());
} Vector3 GetMousePoint()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
bool isCollider = Physics.Raycast(ray, out hit);
if (isCollider)
{
return hit.point;
}
return Vector3.zero;
} #region color
public void OnRedColorChange(bool isOn)
{
if (isOn)
{
paintColor = Color.red;
}
}
public void OnGreenColorChange(bool isOn)
{
if (isOn)
{
paintColor = Color.green;
}
}
public void OnBlueColorChange(bool isOn)
{
if (isOn)
{
paintColor = Color.blue;
}
}
#endregion #region size
public void On1SizeChange(bool isOn)
{
if (isOn)
{
paintSize = 0.1f;
}
}
public void On2SizeChange(bool isOn)
{
if (isOn)
{
paintSize = 0.2f;
}
}
public void On4SizeChange(bool isOn)
{
if (isOn)
{
paintSize = 0.4f;
}
}
#endregion
}

Unity LineRenderer制作画版的更多相关文章

  1. Unity 5 引擎收费版和免费版的区别(转)

    最新Unity 5的Professional Edition(收费版)具备全新而强大的功能,除了全局动态光照或是最新的基于物理的着色器之外,也把原本分开销售的Team License放入,并含有12个 ...

  2. unity 发布web player版,网页打开报Failed to initialize player's 3D settings

    开始时我装的是unity 5.0.0b1,不知道在哪找的这个版本. web player 装的什么版本也忘了. 最后卸载了web player,重新安装web player并另外安装一个unity4. ...

  3. unity资源(移动版)提取 一点尝试

    原地址:http://blog.csdn.net/delguoqing/article/details/22619711 最近在参与一款手游,需要制定美术制作规范.因为拿不准主意,所以决定参考其他游戏 ...

  4. unity LineRenderer

    using UnityEngine; using System.Collections; public class Spider:MonoBehaviour { private LineRendere ...

  5. Unity安装(Windows版)

    Unity下载助手 Unity下载助手是一个小型可执行程序(大小约为1 MB),它允许您选择要下载和安装的Unity Editor的那些组件. 如果你不知道要安装,保留默认选择,单击继续 ,然后按照安 ...

  6. Unity Toast插件(UGUI版)

    简介 介于自己之前经历的一些开发过程,非常希望unity能有类似Toast的功能用于一些简单的信息显示.但是找来找去找了半天,都木有发现,实在是憋不住了,自己写了个,感觉还可以用,发出来共享一下... ...

  7. 1、手写Unity容器--极致简陋版Unity容器

    模拟Unity容器实例化AndroidPhone 思路: 1.注册类型:把类型完整名称作为key添加到数据字典中,类型添加到数据字典的value中 2.获取实例:根据完整类型名称也就是key取出val ...

  8. Unity 4.3 2D 教程:新手上路

    这篇文章译自 Christopher LaPollo 先生的 Unity 4.3 2D 教程的第一部分 Unity 4.3 2D Tutorial: Getting Started 感谢这套优秀教程的 ...

  9. 如何用Unity创建一个的简单的HoloLens 3D程序

    注:本文提到的代码示例下载地址>How to create a Hello World 3D holographic app with Unity 之前我们有讲过一次如何在HoloLens中创建 ...

随机推荐

  1. 【jQuery】结合accordion插件分析写插件的方法及注意事项

    1.jQuery插件的命名方式:jquery.[插件名].js 2.对象方法附加在jQuery.fn上,全局函数附加在jQuery对象本身上 3.插件内部this指向的是通过选择器获取的jQuery对 ...

  2. [XML123] FpML

    Wiki Fpml FpML (Financial products Markup Language) is a business information exchange standard base ...

  3. IE6/IE7不支持first-child的解决办法

    #sidebar li:first-child{ border-top-style:none; } #sidebar li{ border-top-width:1px; border-top-styl ...

  4. 图文助你打开MS SQL Serever的ldf和mdf文件

    第一步:在C盘下找到”program files”双击打开 第二步:打开Microsoft SQL Server 第三步:选择MSSQL.1打开DATA文件 第四步:将你的ldf文件和mdf文件复制到 ...

  5. 使用Apache HttpClient 4.5设置超时时间

    使用HttpClient,一般都需要设置连接超时时间和获取数据超时时间.这两个参数很重要,目的是为了防止访问其他http服务时,由于超时导致自己的应用受影响. 4.5版本中,这两个参数的设置都抽象到了 ...

  6. Jmeter--thrift接口压测,调用jar包失败报错:java.lang.NoSuchMethodError:

    调用thrift接口压测的jar包,出现了错误:java.lang.NoSuchMethodError: 错误可能的原因: 有这个类,该类真的没有这个方法 有这个类,而且有好几个,他们之间发生了冲突 ...

  7. vue-cli3 使用mint-ui

    关于vue-cli3.x按需引入mint-ui问题记录: 按需引入 借助 babel-plugin-component,我们可以只引入需要的组件,以达到减小项目体积的目的. 首先,安装 babel-p ...

  8. docker_Dockerfile_docker hub简单使用搭建nginx

    Docker for Windows是Docker for Microsoft Windows 的Community Edition(CE).要下载Docker for Windows,请前往Dock ...

  9. #leetcode刷题之路32-最长有效括号

    给定一个只包含 '(' 和 ')' 的字符串,找出最长的包含有效括号的子串的长度. 示例 1:输入: "(()"输出: 2解释: 最长有效括号子串为 "()"示 ...

  10. K8S学习心得 == 创建容器influxdb的RC和SVC

    附上:YAML在线检查:http://nodeca.github.io/js-yaml Part 1: 部署Influxdb的RC文件,步骤如下: step 1: influxdb-rc.yaml文件 ...