W
W
Wadim_wadim20002020-06-02 16:02:41
Unity
Wadim_wadim2000, 2020-06-02 16:02:41

Unity - how to stretch a sprite between two points?

https://drive.google.com/file/d/10iG416UY21V206Gpb...
the video showed what the problem is. First, the sprite rotates incorrectly in relation to the "end" of the arrow, which is always directed in the direction of the mouse click. And please help to solve another second question - how to stretch the "middle" arrow sprite from the point sprite to the end of the arrow?

Oh yes, here is the script.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class w : MonoBehaviour
{
    public GameObject arrow_end;
    public GameObject arrow_line;
    public GameObject player;
    public float arrow_offset;
    public float dist;
    void Start()
    {
        arrow_end.SetActive(false);
    }
    void Update()
    {
        if(Input.GetMouseButtonDown(0))
        {
            var mousePos = Input.mousePosition; mousePos.z = 60f;
            var worldPos = Camera.main.ScreenToWorldPoint(mousePos);
            var sprite_pos = player.transform.position;
            var rot_diff = sprite_pos - worldPos;
            var rotation = (Mathf.Atan2(rot_diff.y, rot_diff.x) * Mathf.Rad2Deg) - 0f;

         
            float dist = Vector2.Distance(sprite_pos, worldPos);

            arrow_end.transform.position = worldPos;
            arrow_end.transform.rotation = Quaternion.Euler(0.0f, 0.0f, rotation);
            arrow_end.transform.position += arrow_offset * - arrow_end.transform.up;
            arrow_end.transform.gameObject.SetActive(true);

         
            arrow_line.transform.rotation = Quaternion.Euler(0.0f, 0.0f, rotation);
          

           

        }      
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Kai, 2020-06-03
@Develoder

5ed753a26735c623866798.pngSuper

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question