当前位置:网站首页>Unity-LineRenderer显示一条线
Unity-LineRenderer显示一条线
2022-07-31 21:33:00 【天添向上UT】
01 新建一个line的控件
02 把控件加入脚本
03 通过脚本控制线的颜色,粗细,位置
using UnityEngine;
using System.Collections;
using System.Threading;
using UnityEngine.UI;
public class Demo : MonoBehaviour
{
//游戏对象,这里是线段对象
public GameObject LineRenderGameObject;
//线段渲染器
private LineRenderer lineRenderer;
//两个按钮
public Button btn1;
public Button btn2;
[System.Obsolete]
void Start()
{
//通过游戏对象,GetComponent方法 传入LineRenderer
//就是之前给line游戏对象添加的渲染器属性
//有了这个对象才可以为游戏世界渲染线段
lineRenderer = LineRenderGameObject.GetComponent("LineRenderer") as LineRenderer;
if (lineRenderer != null)
{
//设置线的颜色
lineRenderer.startColor = new Color(0, 0, 255, 1);
lineRenderer.endColor = new Color(0, 0, 255, 1);
//设置线的起点和终点的线的宽度,值越大越宽
lineRenderer.startWidth = 0.05f;
lineRenderer.endWidth = 0.05f;
//画出两条线,取起点(0)和终点(1),起点和终点的位置就是按钮的position,直接获取到了ugui的按钮位置,把它转换为了世界坐标给到了lineRenderer
lineRenderer.SetPosition(0, btn1.transform.position);
lineRenderer.SetPosition(1, btn2.transform.position);
Debug.Log("btn1.transform.position = "+ btn1.transform.position);
}
}
}
04 设置layer看linerender和canvas谁在前面和后面。(因为linerender不是2d物体,不在canvas层)
边栏推荐
- Transfer Learning - Domain Adaptation
- ThreadLocal
- 【论文精读】iNeRF
- AI automatic code writing plugin Copilot (co-pilot)
- Chapter VII
- A few permanent free network transmission, convenient and simple (Intranet through tutorials)
- c语言解析json字符串(json对象转化为字符串)
- 请问我的这段sql中sql语法哪里出了错
- The whole network is on the verge of triggering, and the all-round assistant for content distribution from media people - Rongmeibao
- -xms -xmx(information value)
猜你喜欢
NVIDIA已经开始测试AD106和AD107 GPU核心的显卡产品
财务盈利、偿债能力指标
focus on!Haitai Fangyuan joins the "Personal Information Protection Self-discipline Convention"
Bika LIMS open source LIMS set - use of SENAITE (detection process)
Student management system on the first day: complete login PyQt5 + MySQL5.8 exit the operation logic
21. Support Vector Machine - Introduction to Kernel Functions
Structure of the actual combat battalion module eight operations
Architect 04 - Application Service Encryption Design and Practice
Judging decimal points and rounding of decimal operations in Golang
Realize serial port receiving data based on STM32 ring queue
随机推荐
BM5 合并k个已排序的链表
给定一个ip地址,子网掩码怎么算网络号(如何获取ip地址和子网掩码)
全网一触即发,自媒体人的内容分发全能助手——融媒宝
Flex layout in detail
Socket回顾与I/0模型
The old music player WinAmp released version 5.9 RC1: migrated to VS 2019, completely rebuilt, compatible with Win11
The whole network is on the verge of triggering, and the all-round assistant for content distribution from media people - Rongmeibao
Basic Grammar Introduction of Carbon Tutorial (Tutorial)
focus on!Haitai Fangyuan joins the "Personal Information Protection Self-discipline Convention"
What is Thymeleaf?How to use.
linux view redis version command (linux view mysql version number)
Talking about the algorithm security of network security
A few permanent free network transmission, convenient and simple (Intranet through tutorials)
uni-app中的renderjs使用
Audio alignment using cross-correlation
Chapter Six
Socket Review and I/0 Model
每月一书(202207):《Swift编程权威指南》
Douyin fetches video list based on keywords API
Introduction to Audio Types and Encoding Formats in Unity