Загрузка страницы

Drawing in UNITY in 60 SECONDS

Link to my game: https://play.google.com/store/apps/details?id=com.Hoppo.DodgeMaster

In this 1 minute tutorial you will learn how to implement line drawing, using c# and unity.

Sub to the channel for more usable content that does not waist your precious time.
The code:
using UnityEngine;

public class Draw : MonoBehaviour
{
public Camera m_camera;
public GameObject brush;

LineRenderer currentLineRenderer;

Vector2 lastPos;

private void Update()
{
Drawing();
}

void Drawing()
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
CreateBrush();
}
else if (Input.GetKey(KeyCode.Mouse0))
{
PointToMousePos();
}
else
{
currentLineRenderer = null;
}
}

void CreateBrush()
{
GameObject brushInstance = Instantiate(brush);
currentLineRenderer = brushInstance.GetComponent type_here_angle_brackets LineRenderer type_here_angle_brackets();

//because you gotta have 2 points to start a line renderer,
Vector2 mousePos = m_camera.ScreenToWorldPoint(Input.mousePosition);

currentLineRenderer.SetPosition(0, mousePos);
currentLineRenderer.SetPosition(1, mousePos);

}

void AddAPoint(Vector2 pointPos)
{
currentLineRenderer.positionCount++;
int positionIndex = currentLineRenderer.positionCount - 1;
currentLineRenderer.SetPosition(positionIndex, pointPos);
}

void PointToMousePos()
{
Vector2 mousePos = m_camera.ScreenToWorldPoint(Input.mousePosition);
if (lastPos != mousePos)
{
AddAPoint(mousePos);
lastPos = mousePos;
}
}

}

Видео Drawing in UNITY in 60 SECONDS канала 1 Minute Unity
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
17 июля 2020 г. 19:30:54
00:01:52
Яндекс.Метрика