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
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
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
![How To Draw a Line in Unity | Line Renderer | Unity Quick Tips #3](https://i.ytimg.com/vi/5ZBynjAsfwI/default.jpg)
![60 Seconds Tutorial | Launching Game Objects With Mouse | Unity 2D](https://i.ytimg.com/vi/ItcW0TreC18/default.jpg)
![Display Glowing NavMesh Path in Unity - #3 Displaying the path](https://i.ytimg.com/vi/dTlSk9cP7TA/default.jpg)
![Unity Mobile Dev from Scratch: Drawing on the Screen](https://i.ytimg.com/vi/cHVZ0SYIHkI/default.jpg)
![Unity Drawing on the Screen 2019](https://i.ytimg.com/vi/fpve8fT2aB8/default.jpg)
![Implement Drawing and Saving in Unity 2018 🎮 HD](https://i.ytimg.com/vi/DCD8Pt1zf4c/default.jpg)
![Collisions and Triggers ("OnTriggerEnter not working!")](https://i.ytimg.com/vi/Bc9lmHjqLZc/default.jpg)
![Unity Draw Line Renderers with Physics, like Love balls game](https://i.ytimg.com/vi/KojYeZwEPyQ/default.jpg)
![Create a 2D laser in 60 seconds UNITY](https://i.ytimg.com/vi/vdci2oxVaoA/default.jpg)
![Unity Drawing Lines with Mouse Position - Line Renderer and Edge Collider](https://i.ytimg.com/vi/pa_U64G7gkE/default.jpg)
![UNITY Create a top down shooter in 120 SECONDS](https://i.ytimg.com/vi/bJ5XX7R74vs/default.jpg)
![Unity Mobile From Scratch: Drawing Multiple Lines](https://i.ytimg.com/vi/xlwuGKTyJBs/default.jpg)
![Creating a UI Line Renderer in Unity](https://i.ytimg.com/vi/--LB7URk60A/default.jpg)
![Create YOUR OWN Custom Planet Gravity UNITY 2D](https://i.ytimg.com/vi/e4DxQhTKJ7Y/default.jpg)
![Top 15 Tips & Tricks in Among Us | Ultimate Guide To Become a Pro #4](https://i.ytimg.com/vi/ZcEu_logAQI/default.jpg)
![Unity Ragdoll Tutorial - Ragdoll Physics - Gang Beasts Style - Part 1](https://i.ytimg.com/vi/I1beTn_913c/default.jpg)
![CREATE A CHECK POINT / WAY POINT MAP UI WITH CANVAS LINE RENDERER - UNITY TUTORIAL](https://i.ytimg.com/vi/m2rISkZGrPY/default.jpg)
![Create a beautiful, stylized nature environment in Unity, in 3 minutes](https://i.ytimg.com/vi/hZy2d8fJs1M/default.jpg)
![Coding Adventure: Simulating an Ecosystem](https://i.ytimg.com/vi/r_It_X7v-1E/default.jpg)
![Draw Lines in Unity using LineRenderer | Tutorial](https://i.ytimg.com/vi/FipeYR8KdF0/default.jpg)