public class Bow : MonoBehaviour {
public GameObject line;
public float maxStretchDistance;
float currentStretchDistance;
Vector3 mousePosition;
Vector3 bowDirection;
Vector3 mousePositionInRelationToLineCenter;
void Update() {
mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition) + Vector3.forward * 10;
mousePositionInRelationToLineCenter = mousePosition - line.transform.position;
}
void OnMouseDrag()
{
bowDirection = -(mousePosition - this.transform.position);
bowDirection.Normalize();
transform.right = bowDirection;
line.GetComponent<LineRenderer>().SetPosition(1, mousePositionInRelationToLineCenter);
}
void OnMouseUp()
{
line.GetComponent<LineRenderer>().SetPosition(1, Vector3.zero);
}
}
[attachment=34889:Bow.gif]
As you can see the problem is with the line renderer.
I have a variable that save the mouse position in relation to the line center and I am trying to use this variable to move the line center.
I don't know what is wrong in my code, help me please.
Thank you in advance