I am trying to return a value between 0 and 1 whenever user is clicking on holding the left mouse button over a collision object called "RightPull". This is what i have so far.
var RPullValue : float = 0.0;
function Update()
{
if (Input.GetMouseButtonDown(0))
{
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, hit)){
if (hit.collider.name == "RightPull"){
hit.rigidbody.AddForce (-hit.normal * 100);
RPullValue += Input.GetAxis("Mouse Y") *0.01;
}
}
}
}
This works to an extent. The extent is that it only registers a value increase for one moment when the user clicks, but not when you drag the mouse. Other issues are that the value can increase or decrease beyond 0 and 1. Any ideas how I can get this value to adjust more smoothly and interactively?
I can use a clamp value to limit the value between 0 and 1, but this answer still does not address how I can limit the mouse input to only be effected when the mouse button is held over the collider.
– anon58197044