• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Kirpich158 · Jun 03 at 12:13 AM · 2d game2d spritesline drawing

How to create a line with a repeated sprite on 2d map between 2 points

Hello there, tried to use LineRenderer for that, but without a good result. The thing is, that I need to draw a line with my own sprite, which looks like a little arrow, between two points on the map, but when I tried to use LineRenderer, sometimes it adds half of an arrow if the distance need it, but I want to add and draw only full sprites. So I think maybe about just adding these sprites by instantiating prefabs with Sprite Renderer having this sprite (but now as I'm writing this, I think that there will be a lot o these prefabs, cause map will be big, like in Slay the Spire, so it could impact performance). So what do you guys think or how can you help me, will appreciate every feedback and help. Thx <3

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by AaronBacon · Jun 03 at 12:39 AM

I'd Look into Slicing Sprites, It's typically used for UI, with borders that stay consistent on a resizeable UI box, but I've used it for an arrow with a sprite before. You simply set up the Arrow sprite in the sprite Editor so that the arrow head is outside the green box and considered a border. You also likely want to set it's pivot point to be at the base of the arrow (0.5,0 in my case below):

⠀

link text

⠀

Then You make the sprite and set its Draw Mode to Tiled

⠀

link text

⠀

And now you can resize it and it should keep the arrow head while still resizing the line:

⠀ link text

⠀

Quick Note for scripting, You have to Modify the Sprite Renderers size property, not its scale. Here's a Script I wrote a While back that should make the arrow go from 1 point to another:

 public class ArrowScript: MonoBehaviour
 {
     public Transform startPoint;
     public Transform endPoint;
     private Vector3 offset;
     private SpriteRenderer spr;
 
     // Awake is called when the script instance is being loaded.
     protected void Awake()
     {
         offset = new Vector3(0,90,90);
         spr = GetComponent<SpriteRenderer>();
     }
     
     void FixedUpdate()
     {
         if(startPoint != null)
         {
             transform.position = startPoint.position;
             transform.LookAt(endPoint);
             transform.Rotate(offset);
             spr.size = new Vector2(spr.size.x, Vector3.Distance(startPoint.position,endPoint.position));
         }
     }
 }

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kirpich158 · Jun 03 at 01:04 AM 0
Share

it's pretty awesome dude, but I have a sprite that looks like an arrow head, so this arrow head should be repeated, so there are a couple of them between the points, not like the line before a normal arrow as you show on gif. idk if I'm describing it well and clear?

avatar image AaronBacon Kirpich158 · Jun 03 at 02:03 AM 1
Share

In that case just skip the First step of setting the Sprite Borders (Green Box). If you just set its pivot and make the sprite tiled, the sprite will repeat as a whole

avatar image Kirpich158 AaronBacon · Jun 03 at 10:34 AM 0
Share

ok, thx, I will try to repeat it today, thx <3

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

192 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Best approach for 2d animation to interact with the environment? 0 Answers

My 2D Player Can't Move (2d Photon Game) :(,My Player Don't Move (2d Character Controller 0 Answers

Can anybody help me with this? Character bodying is falling apart. 0 Answers

How do i make my 2d character move one step at a time? 1 Answer

2D graphic problem with tilemap and resolution 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges