Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the effect of Writing on screen by unity

Shulou Source: shulou.com Published: 2022-06-03 09:21:03 10月03日 Update

This article mainly introduces unity how to achieve the effect of writing on the screen, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

The details are as follows

First create a RawImage, then add a LineRenderer component to the picture, then create a shader, change the Shader of the shader to Particles/Additive, drag the shader to Materials/Element 0 of the LineRenderer component, and finally drag the code to the empty object. The Target of the code is RawImage, and the following code

Using System.Collections;using System.Collections.Generic;using UnityEngine;public class huaxian: MonoBehaviour {private GameObject clone;private LineRenderer line;int ibank / with LineRender object public GameObject target;void Start () {Debug.Log ("Please start writing");} / / Update is called once per frame void Update () {if (Input.GetMouseButtonDown (0)) {/ / instantiate object clone = (GameObject) Instantiate (target, target.transform.position, Quaternion.identity) / / get the LineRender components on the object line = clone.GetComponent (); / / set the start and end colors line.SetColors (Color.red, Color.blue); / / set the width of the start and end line.SetWidth (0.2f, 0.1f); / / count I = 0;} if (Input.GetMouseButton (0)) {/ / detect each frame, the longer you press the mouse, the more iComplete + / / set the number of vertices line.SetVertexCount (I); / / set the vertex position (index of vertices, convert the screen coordinates of mouse clicks into world coordinates) line.SetPosition (I-1, Camera.main.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, 15));}

Thank you for reading this article carefully. I hope the article "how to achieve the effect of unity writing on screen" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Articles screens writing code materials objects components effects coordinates vertices mouse start world value location interest content at the same time pictures examples Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft MariaDB Apple Xiaomi Shulou Tech Info