当前位置:网站首页>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层)
边栏推荐
- PCB stackup design
- uni-app中的renderjs使用
- spark reports an error OutOfMemory "recommended collection"
- linux view redis version command (linux view mysql version number)
- 返回一个零长度的数组或者空的集合,不要返回null
- IDA PRO中汇编结构体识别
- "The core concept of" image classification and target detection in the positive and negative samples and understanding architecture
- SiC MOSFET的短路特性及保护
- What's wrong with the sql syntax in my sql
- leetcode 665. Non-decreasing Array 非递减数列(中等)
猜你喜欢
利用反射实现一个管理对象信息的简单框架
Implementing a Simple Framework for Managing Object Information Using Reflection
20. Support vector machine - knowledge of mathematical principles
Efficient Concurrency: A Detailed Explanation of Synchornized's Lock Optimization
Write a database document management tool based on WPF repeating the wheel (1)
C程序设计-方法与实践(清华大学出版社)习题解析
Chapter VII
【PIMF】OpenHarmony 啃论文俱乐部—盘点开源鸿蒙三方库【3】
Apache EventMesh distributed event-driven multi-runtime
Count characters in UTF-8 string function
随机推荐
一款国外开发的高质量WordPress下载站模板主题
Flex layout in detail
Qualcomm cDSP simple programming example (to query Qualcomm cDSP usage, signature), RK3588 npu usage query
[NLP] What is the memory of the model!
Mobile web development 02
Shell 脚本 快速入门到实战 -02
Student management system on the first day: complete login PyQt5 + MySQL5.8 exit the operation logic
【愚公系列】2022年07月 Go教学课程 025-递归函数
统计UTF-8字符串中的字符函数
【论文精读】iNeRF
Carbon教程之 基本语法入门大全 (教程)
PCB stackup design
Batch (batch size, full batch, mini batch, online learning), iterations and epochs in deep learning
21. Support Vector Machine - Introduction to Kernel Functions
架构实战营模块八作业
Several methods for deleting specified elements in Golang slices
BM3 将链表中的节点每k个一组翻转
leetcode 665. Non-decreasing Array 非递减数列(中等)
sqlite3 simple operation
Judging decimal points and rounding of decimal operations in Golang