'How do I Move My Mouse Position With a Scrollbar?
I have a lot of dots that move, depending on the mouse position. I would like to change it so that it moves with the scrollbar value. How could I implement something like this?
I have tried giving my direction value direction = scrb.value - bowpos;
instead of mousepos
, but that gives me an error.
void Update()
{
Vector2 bowpos = transform.position;
Vector2 mousepos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
direction = mousepos - bowpos;
FaceMouse();
for (int i = 0; i < Points.Length; i++)
{
Points[i].transform.position = Pointposition(i * 0.1f);
}
}
My Code:
public class arrowproject : MonoBehaviour
{
Vector2 direction;
public float force;
public GameObject PointPrefab;
public GameObject[] Points;
public int numberofpoints;
public bool dotss = false;
public Scrollbar scrb;
// Start is called before the first frame update
void Start()
{
Points = new GameObject[numberofpoints];
for (int i = 0; i < numberofpoints; i++)
{
Points[i] = Instantiate(PointPrefab, transform.position, Quaternion.identity);
}
}
// Update is called once per frame
void Update()
{
Vector2 bowpos = transform.position;
Vector2 mousepos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
direction = mousepos - bowpos;
FaceMouse();
for (int i = 0; i < Points.Length; i++)
{
Points[i].transform.position = Pointposition(i * 0.1f);
}
}
void FaceMouse()
{
transform.right = direction;
}
Vector2 Pointposition(float t)
{
Vector2 currentPointpos = (Vector2)transform.position + (direction.normalized * force * t) + 0.5f * Physics2D.gravity * (t * t);
return currentPointpos;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|