ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

UNITY两个物体之间画线功能实现(UNITY LINE RENDERER组件理解)

2022-01-20 16:32:21  阅读:527  来源: 互联网

标签:Unity lineRenderer UNITY Renderer Line 阴影 LINE 线条 RENDERER


假如要在这两个物体中间画线的话

 

 

 

 要做的就是往顶层节点clock上添加组件Line Renderer

 

 添加结束后如图,比较重要的各个属性介绍
Cast Shadows 确定线是否投射阴影,是否应从线的一侧或两侧投射阴影,或线是否只投射阴影而不被绘制
Positions 这些属性描述了一个指向connec的向量3点数组就是画线的终点和起点,里面可以加很多点,此例加两个点,三点数组,所以我们要得到起点的位置和终点的位置,在clock的代码中声明两个Transform,拖入那两个节点就行
Color 用渐变来控制线条的颜色
Width 中间的图是用来调整设置线的宽度
Material 这些属性描述了用于绘制线条的材料数组。这条线将为数组中的每个材质绘制一次
Corner vertices 此属性指示在绘制线条中的角时使用多少额外的顶点。增加这个值使线条角看起来更圆
End Cap Vertices此属性指示在行上使用多少额外的顶点来创建结束符。增加这个值使行帽看起来更圆
Alignment 设置为“View”使线面向摄像机,或设置为“局部”使线基于变换组件的方向进行对齐
Texture Mode 控制纹理如何应用到线条上。使用Stretch将纹理映射应用于整个线条的长度,或者使用Wrap使纹理沿着线条的长度重复。使用材料的平铺参数来控制重复率
Shadow Bias 沿着光的方向移动阴影,以去除阴影的工件

 

 就这个意思
具体代码就很好实现了,主要是要每时每刻更新两个子节点的位置,因为这种东西都是动的

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Line : MonoBehaviour
{
    LineRenderer lineRenderer;
    public  Transform start;
    public Transform end;
    void Start()
    {
        lineRenderer = GetComponent<LineRenderer>();
    }
 
    // Update is called once per frame
    void Update()
    {
        lineRenderer.SetPosition(0, start.position);
        lineRenderer.SetPosition(1, end.position);
    }
}
 

Details

To create a Line Renderer:

In the Unity menu bar, go to GameObject

Create Empty
In the Unity menu bar, go to Component
Effects > Line Renderer
Drag a Texture or Material onto the Line Renderer. It looks best if you use a Particle Shader in the Material.
Hints
Line Renderers are useful for effects where you need to lay out all the vertices in one frame.
The lines might appear to rotate as you move the Camera. This is intentional when Alignment is set to View. Set Alignment to Local to disable this.
The Line Renderer should be the only Renderer on a GameObject.
Unity samples colors from the Color Gradient at each vertex. Between each vertex, Unity applies linear interpolation to colors. Adding more vertices to your Line Renderer might give a closer approximation of a detailed Color Gradient.

标签:Unity,lineRenderer,UNITY,Renderer,Line,阴影,LINE,线条,RENDERER
来源: https://www.cnblogs.com/guangzhiruijie/p/15826858.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有