Thanks for the tutorial! I do not know if there would be any performance impact but this 4:20 can be also achieved with a Coroutine, with a yield return WaitForSeconds of 1/fps and changing the texture on each step instead of using Time.deltaTime. In this case it doesn't need to verify the fps counter every frame. Also, since the FPS of the animation is a constant value, 1f/fps doesn't need to be calculated on each frame, it can be solved in the Awake method and use a variable in the Update / Coroutine.
Hey, got this working. For anyone who gets annoyed at stretching pixels, make sure your sprite/image "Wrap Mode" is set to "Repeat", default is "Clamp" I believe....stretchy stuff. Also, if anyone has a solution for using packed sprites, let me know. As yet, I can't find a way to read the slices in a packed sprite after slicing with the sprite editor. I tried using a Sprite Atlas but the Line Renderer gets the entire atlas, even if you use individual sprite frames.
Why can't unity themselves provide tutorials like this. Super helpful, thanks! Is there any way to have the texture repeat every n units, rather than per unit?
You can add this little code: // width is the width of the line float width = lineRenderer.startWidth; lineRenderer.material.mainTextureScale = new Vector2(1f / width, 1.0f); // 1/width is the repetition of the texture per unit (thus you can also do double // lines)
I need help. I've been unsuccessfully trying to add a line of code that updates the firing position of this Tesla coil object when it's moving on the screen, and I want to adapt it for a moving spaceship.
@@_Vesper Thanks. But it looks wider. imgur.com/a/JYPGRzE I want to keep aspect ratio. For now, I'm dealing with this problem by making sprite bigger. (4Pixel in 1Pixel)
Hi! I used Krita, it's free and is great for animation. I used the technique I explained in this video: ruclips.net/video/V7VjId-77BM/видео.html. So I draw a frame and make sure it wraps on both ends, then do the same for the next frame.
Thank you for the video, it was great, Question: I need a laser for a disco ball-type effect like in Royal Match for mobile 2d urp game , I also need a way to determine the Line Renderer color, ensuring it has different colors when a player chooses a specific color. Does anyone know or can provide a clue or link on how to achieve that?"
I have this error right after finishing the Weapon script The type or namespace name 'Creature' could not be found (are you missing a using directive or an assembly reference?) I imagine I have to somehow import the Creature prefab into the script, but I don't know how. I have been following the tutorial and I don't see any difference. Please help!
following the steps up till 3 minutes, the lightning texture is stretched horizontally along the line. it repeats too, but it's still stretched, it's also really thin. this is on unity 2022 URP. Anyone know how to fix? both the texture and material previews look as expected and ive triple checked all my settings against the video.
You can cycle through different ones. If you want to use them in the same line at the same time, you could split the line into 2, just start the second one where the first one ends with a different material.
sorry, I don't know a way to do that, I haven't played around with it for a while. Would be pretty cool though, you could have those electric lines and send little energy balls from start to finish.
This tutorial helped me a bunch, but I'd love to get more control over these animations. Where could I learn this? Because this isn't using Unity's standard animation tool that I keep finding tutorials on. Thank you!!!
Is there any way to add functionality like clicking on these lines? As far as I understand unity I think that requires a collider, however ,the colliders do not fit the lines.
You could just use a box collider and stretch it by scaling it. If you mean clicking on these lines very precisely, close to the pixel, you would have to make a polygon collider for each sprite and loop through it just like we do with the sprites.
Nice tutorial! Does anyone know the way to have the same result but with first and last sprites staying the same. I want to make a double edged arrow line so that middle part stretches but end points stay as arrows (like a dimesnsion tool).
Is this for UI? In that case it would be very easy with slicing the sprite. For ingame/line renderer you could just place the ends by script and use the line renderer only for the middle part.
@@ShackMan Not not for UI. It's ingame object. I managed to do it in a different way. I created double arrow sprite and made border so that only middle part extends. And instead of line renderer I used regular sprite renderer and use it's size.x value. You just have to position sprite renderer gameobject in the middle and increase size.x which autotiles from the middle and creates custom length arrow.
This error appears, please help me \Bio-TecN\SCRIPT\Weapon.cs(26,24): error CS0029: Cannot implicitly convert type 'Creature[]' to 'System.Collections.Generic.List' allCreatures = Resources.FindObjectsOfTypeAll();
like this? allCreatures = Resources.FindObjectsOfTypeAll()ToList(); Errors continue to appear on this line, an error also appears when I change from ''Count'' to ''Length'' on another line as shown in the video at 13:59. for (int i = 0; i < allCreatures.Count; i++)
@@CortesVidaSaudavel645 You forgot a . between () and ToList(). Count and Length is because of array vs list. Google a bit about the differences, there are many articles about it.
@@ShackMan I saw now that later on you eliminated this first line and kept ''Count'' in the other. I put a 2d collider and a Tag in ''Line Renderer'' so that the player who touches any point in the radius will be destroyed, but it's not working. How could I do it? Because I adapted this example to a kind of barrier in a ''Shoot in Up'' style ship game where two ships create this plasma arc to destroy the player if he touches anywhere on the line.
@@ShackMan Thank you so much for your reply, I want to make a writing type game , In which player move the finger on the screen in the shapes of alphabet obviously, and the shapes are made , Till now I used line renderer on mouse position...but there's one main problem in this approach that is the line looks normal drawing, and I want to give cursive writing feel to the player.
If I understand correctly, you would simply have to use a lot of points in the line renderer, so it appears to a be a round line even though it's just a lot of small straight lines. If you want the user to draw a letter by hand and your game recognizes which letter that was, that would be a lot more complicated.
@@ShackMan Yeah , I tried width curve and line points , different points break but nothing looking good, Btw thank you so much you look into this, I will try something ....
No, update is called as often as possible. Unity calls every script that has an Update method, and when everything that was effected by those methods finishes, a frame is put on the screen. Then the loop runs again. Try to research a bit more into it. It can be confusing at first (it was for me), but once you understand the concept of update loops in Unity, it is very useful.
@@ShackMan The thing is, I'm using a nodecanvas system where the OnUpdate method is called every frame. But when I put a debug in there, I only got 60 debugs back. The exit condition was : protected override void OnUpdate() { Debug.LogError("updateCall"); if (remainingTime
@@ShackMan Ok I've solved it by removing from deltatime and checking with if (remainingTime 2/100 ... I found out that the OnUpdate method was only called when the child nodes were updated. I wonder if there is a better way of doing this thing in general. Like not changing the material texture.
You'd just move the line where the line renderer is instantiated in the Update method where we check for input. And also keep a reference to it with a field (for example activeLine), so when another key is pressed we can call Destroy and pass in the activeLine.gameObject). One problem here is thought that if you create more than one, you only have a reference to the last one created and can only destroy that. Depending on what you are trying to achieve, this might be enough though. private LineController activeLine; private void Update() { if (Input.GetKeyDown(KeyCode.Space)) activeLine = Instantiate(linePrefab); if (Input.GetKeyDown(KeyCode.Enter)) Destroy(activeLine.gameObject); }
@@ShackMan that worked! thank you. I wanted my Player who was mobile to be able to do this, but to different objects that would connect to each other (using the line). This is a great starting off point - can't wait to learn more from your channel
You mean using an animation clip, right? I haven't tried it out, since this is exactly what animation (2D) does, it just swaps the sprites. But of course it is much easier to edit animations and add stuff like rotation.
"we can't see shit" and "reduce depression" killed me, absolutely unexpected deadpan delivery. Great video.
This is low-key one of the most useful unity channels 👍🏼
Thanks!
Thanks for the tutorial! I do not know if there would be any performance impact but this 4:20 can be also achieved with a Coroutine, with a yield return WaitForSeconds of 1/fps and changing the texture on each step instead of using Time.deltaTime. In this case it doesn't need to verify the fps counter every frame. Also, since the FPS of the animation is a constant value, 1f/fps doesn't need to be calculated on each frame, it can be solved in the Awake method and use a variable in the Update / Coroutine.
Big like! I were looking for such this tutorial so long, You made my day. Thanks a lot
Thank you for this ill keep watching you
Hey, got this working.
For anyone who gets annoyed at stretching pixels, make sure your sprite/image "Wrap Mode" is set to "Repeat", default is "Clamp" I believe....stretchy stuff.
Also, if anyone has a solution for using packed sprites, let me know.
As yet, I can't find a way to read the slices in a packed sprite after slicing with the sprite editor.
I tried using a Sprite Atlas but the Line Renderer gets the entire atlas, even if you use individual sprite frames.
@@Massive-3D imagine being called a dork for trying to be helpful. Uninstalling care.exe
@@everlastingmedia Imagine thinking I give a shit. Everlasting Media but has ZERO media. Good job with all that.
Thanks a lot man!
godbless you.
I have set the sprite/image to Wrap Mode but still I get the stretched pixel. Using unity 2022 btw.
Hey Shack Just tumbled across your videos. They are great and found all the things that I want in them. Great work
Why can't unity themselves provide tutorials like this. Super helpful, thanks!
Is there any way to have the texture repeat every n units, rather than per unit?
Tbf there's literally infinite things Unity could make a tutorial on
You can add this little code:
// width is the width of the line
float width = lineRenderer.startWidth;
lineRenderer.material.mainTextureScale = new Vector2(1f / width, 1.0f);
// 1/width is the repetition of the texture per unit (thus you can also do double
// lines)
Nice video
nice music :-)
Very helpful Sir 👍, It is also solved the problem that I was in from weeks.
Thanks a lot! I'm going to use this in 3d for a jam game.
Cool, can you send me a link when it's done?
@@ShackMan Unfortunately ran out of time before I could implement it. Will do in the future.
@@sohrabhamza3805 Running out of time is part of a game jam ;-)
@@ShackMan haha true!
I need help. I've been unsuccessfully trying to add a line of code that updates the firing position of this Tesla coil object when it's moving on the screen, and I want to adapt it for a moving spaceship.
Helped me in my project ! Thank You
When I destroy the mosnter and want to destroy the line attached to that monster. How Can i know which line should I destroy? Thanks
thank you please more simple tutorials like this
Great tutorial! Thx.
How can I change scale of line texture?
My texture looks too tiny on line renderer.
Change the width of the line either in the inspector with the graph, or in script with lineRenderer.widthMultiplier = ...
@@_Vesper
Thanks.
But it looks wider.
imgur.com/a/JYPGRzE
I want to keep aspect ratio.
For now, I'm dealing with this problem by making sprite bigger. (4Pixel in 1Pixel)
Thanks for the guide,
what tool did you use to create the tiled image for the lightning arc?
Hi! I used Krita, it's free and is great for animation. I used the technique I explained in this video: ruclips.net/video/V7VjId-77BM/видео.html.
So I draw a frame and make sure it wraps on both ends, then do the same for the next frame.
@@ShackMan Awesome, thanks
Thank you for the video, it was great,
Question:
I need a laser for a disco ball-type effect like in Royal Match for mobile 2d urp game , I also need a way to determine the Line Renderer color, ensuring it has different colors when a player chooses a specific color. Does anyone know or can provide a clue or link on how to achieve that?"
Hey bro, why the function tile not work? just put the texture and on the final texture just strecht over the finals pixels
I have this error right after finishing the Weapon script
The type or namespace name 'Creature' could not be found (are you missing a using directive or an assembly reference?)
I imagine I have to somehow import the Creature prefab into the script, but I don't know how. I have been following the tutorial and I don't see any difference. Please help!
It means that there is no script called 'Creature'. Did you use custom namespaces and put it in another one?
This has helped me a lot! Thank you so much!
Is there a way I could tell the animation to stop after its played every sprite?
following the steps up till 3 minutes, the lightning texture is stretched horizontally along the line. it repeats too, but it's still stretched, it's also really thin. this is on unity 2022 URP. Anyone know how to fix? both the texture and material previews look as expected and ive triple checked all my settings against the video.
did u solve it?
we can use multiples material in the same line, using de index lenght?
You can cycle through different ones. If you want to use them in the same line at the same time, you could split the line into 2, just start the second one where the first one ends with a different material.
Thank you so much bro! You saved my life
Can you do a f18 fighter plane H.U.D display.where a target icon on the canvas follows tank or other fighter plane in the sky in the 3d environment?
Awesome vid, helped a lot!
Is there a way to change the tiles of the line individually, so that the line consists of different images?
sorry, I don't know a way to do that, I haven't played around with it for a while. Would be pretty cool though, you could have those electric lines and send little energy balls from start to finish.
For some reason there is a huge gap between the tiles in my line :/
This tutorial helped me a bunch, but I'd love to get more control over these animations. Where could I learn this? Because this isn't using Unity's standard animation tool that I keep finding tutorials on. Thank you!!!
Nice video!
Is there any way to add functionality like clicking on these lines? As far as I understand unity I think that requires a collider, however ,the colliders do not fit the lines.
You could just use a box collider and stretch it by scaling it. If you mean clicking on these lines very precisely, close to the pixel, you would have to make a polygon collider for each sprite and loop through it just like we do with the sprites.
@@ShackMan Thanks!
Nice tutorial! Does anyone know the way to have the same result but with first and last sprites staying the same. I want to make a double edged arrow line so that middle part stretches but end points stay as arrows (like a dimesnsion tool).
Is this for UI? In that case it would be very easy with slicing the sprite. For ingame/line renderer you could just place the ends by script and use the line renderer only for the middle part.
@@ShackMan Not not for UI. It's ingame object. I managed to do it in a different way. I created double arrow sprite and made border so that only middle part extends. And instead of line renderer I used regular sprite renderer and use it's size.x value. You just have to position sprite renderer gameobject in the middle and increase size.x which autotiles from the middle and creates custom length arrow.
Big like bro big like ❤🥰
This error appears, please help me \Bio-TecN\SCRIPT\Weapon.cs(26,24): error CS0029: Cannot implicitly convert type 'Creature[]' to 'System.Collections.Generic.List'
allCreatures = Resources.FindObjectsOfTypeAll();
FindObjectsOfType returns an array, allCreatures seems to be a list. Simply add 'ToList() right before the semicolon.
like this? allCreatures = Resources.FindObjectsOfTypeAll()ToList();
Errors continue to appear on this line, an error also appears when I change from ''Count'' to ''Length'' on another line as shown in the video at 13:59.
for (int i = 0; i < allCreatures.Count; i++)
@@CortesVidaSaudavel645 You forgot a . between () and ToList().
Count and Length is because of array vs list. Google a bit about the differences, there are many articles about it.
@@ShackMan I saw now that later on you eliminated this first line and kept ''Count'' in the other.
I put a 2d collider and a Tag in ''Line Renderer'' so that the player who touches any point in the radius will be destroyed, but it's not working. How could I do it? Because I adapted this example to a kind of barrier in a ''Shoot in Up'' style ship game where two ships create this plasma arc to destroy the player if he touches anywhere on the line.
Thanks man !
YOU SAVE ME Thank a lot!
Awersome, thanks
how can i get cursive writing or caliigraphic writing effect please help?
Can you explain in more detail? Not sure what you mean exactly. Greetings
@@ShackMan
Thank you so much for your reply,
I want to make a writing type game , In which player move the finger on the screen in the shapes of alphabet obviously, and the shapes are made ,
Till now I used line renderer on mouse position...but there's one main problem in this approach that is the line looks normal drawing, and I want to give cursive writing feel to the player.
If I understand correctly, you would simply have to use a lot of points in the line renderer, so it appears to a be a round line even though it's just a lot of small straight lines.
If you want the user to draw a letter by hand and your game recognizes which letter that was, that would be a lot more complicated.
@@ShackMan
Yeah , I tried width curve and line points , different points break but nothing looking good,
Btw thank you so much you look into this, I will try something ....
What if I want to change more than 60 textures in 1 second? The update is being called only 60 times.
No, update is called as often as possible. Unity calls every script that has an Update method, and when everything that was effected by those methods finishes, a frame is put on the screen. Then the loop runs again. Try to research a bit more into it. It can be confusing at first (it was for me), but once you understand the concept of update loops in Unity, it is very useful.
@@ShackMan The thing is, I'm using a nodecanvas system where the OnUpdate method is called every frame. But when I put a debug in there, I only got 60 debugs back. The exit condition was :
protected override void OnUpdate()
{
Debug.LogError("updateCall");
if (remainingTime
@@ShackMan Ok I've solved it by removing from deltatime and checking with
if (remainingTime 2/100 ...
I found out that the OnUpdate method was only called when the child nodes were updated. I wonder if there is a better way of doing this thing in general. Like not changing the material texture.
awesome tutorial! what if you wanted to destroy the linePrefabs and just spawn new ones each time you press the button?
You'd just move the line where the line renderer is instantiated in the Update method where we check for input. And also keep a reference to it with a field (for example activeLine), so when another key is pressed we can call Destroy and pass in the activeLine.gameObject). One problem here is thought that if you create more than one, you only have a reference to the last one created and can only destroy that. Depending on what you are trying to achieve, this might be enough though.
private LineController activeLine;
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
activeLine = Instantiate(linePrefab);
if (Input.GetKeyDown(KeyCode.Enter))
Destroy(activeLine.gameObject);
}
@@ShackMan that worked! thank you. I wanted my Player who was mobile to be able to do this, but to different objects that would connect to each other (using the line). This is a great starting off point - can't wait to learn more from your channel
what I understand is that you just change the texture of line continuously. Can we assign animation to the line renderer?
You mean using an animation clip, right? I haven't tried it out, since this is exactly what animation (2D) does, it just swaps the sprites. But of course it is much easier to edit animations and add stuff like rotation.
@@ShackMan yeah because I want to make it look like particles. I dont know changing length of the particle is possible.
Thank you!
ehh why tiling not work?
recheck your Wrap Mode 0:50
god
For the trick @2:40 What the heck Unity!
"As you can see, we can't see shit" LOL
3 years of unity and never used the lock inspector icon. lol wow
"We can't see shit"😂