当前位置:网站首页>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层)


边栏推荐
- TestCafeSummary
- ThreadLocal
- Memblaze发布首款基于长存颗粒的企业级SSD,背后有何新价值?
- LevelSequence source code analysis
- Book of the Month (202207): The Definitive Guide to Swift Programming
- grep命令 笔试题
- Architecture Battalion Module 8 Homework
- C language parsing json string (json object is converted to string)
- A few permanent free network transmission, convenient and simple (Intranet through tutorials)
- How to change npm to Taobao mirror [easy to understand]
猜你喜欢

Socket回顾与I/0模型

顺序表的实现

NVIDIA has begun testing graphics products with AD106 and AD107 GPU cores

请问我的这段sql中sql语法哪里出了错

A shortcut to search for specific character content in idea

老牌音乐播放器 WinAmp 发布 5.9 RC1 版:迁移到 VS 2019 完全重建,兼容 Win11

Introduction to Audio Types and Encoding Formats in Unity

ECCV 2022 Huake & ETH propose OSFormer, the first one-stage Transformer framework for camouflaging instance segmentation!The code is open source!...

The principle of ReentrantLock (to be continued)

The whole network is on the verge of triggering, and the all-round assistant for content distribution from media people - Rongmeibao
随机推荐
BM5 merge k sorted linked lists
财务盈利、偿债能力指标
深度学习中的batch(batch size,full batch,mini batch, online learning)、iterations与epoch
A solution to the server encountered an internal error that prevented it from fulfilling this request [easy to understand]
C language parsing json string (json object is converted to string)
The whole network is on the verge of triggering, and the all-round assistant for content distribution from media people - Rongmeibao
Returns a zero-length array or empty collection, do not return null
Structure of the actual combat battalion module eight operations
Linux environment redis cluster to build "recommended collection"
给定一个ip地址,子网掩码怎么算网络号(如何获取ip地址和子网掩码)
Douyin fetches video list based on keywords API
MATLAB program design and application 2.4 Common internal functions of MATLAB
Financial profitability and solvency indicators
Golang must know the Go Mod command
ECCV 2022 Huake & ETH propose OSFormer, the first one-stage Transformer framework for camouflaging instance segmentation!The code is open source!...
Chapter Six
How to identify fake reptiles?
Shell 脚本 快速入门到实战 -02
Several methods for deleting specified elements in Golang slices
What is Thymeleaf?How to use.