Hi, I have a normal grab and throw script when the player grabs the ball the boolean switch to true same as the animation the script works perfectly but I have multiple players and when two or more players get to the ball and grab it at the same time all of the players isGrabed boolean and the animation switch to true but I wanted is just to make the boolean equal to true for only one object, in other words, I want the boolean equal to true for only one object.
public class test : MonoBehaviour
{
public float distance = 0f;
public Transform holdpoint;
public Transform disPos;
public LayerMask grabbable;
[HideInInspector]
public Transform currentlyGrabbedObject;
public bool isGrabed;
public float throwForce;
public Animator anim;
void Update()
{
if (Input.GetKeyDown(KeyCode.E))
{
var throwing = new Vector2(transform.localScale.x, 2) * throwForce;
if (!currentlyGrabbedObject)
{
Collider2D hit = Physics2D.OverlapCircle(disPos.position, distance, grabbable);
if (hit)
{
currentlyGrabbedObject = hit.transform;
isGrabed = true;
}
}
else
{
currentlyGrabbedObject.gameObject.GetComponent<Rigidbody2D>().velocity = throwing;
currentlyGrabbedObject = null;
isGrabed = false;
}
}
if (currentlyGrabbedObject)
{
currentlyGrabbedObject.position = holdpoint.position;
}
if (isGrabed == true)
{
anim.SetBool("isGrabed", true);
}
else
{
anim.SetBool("isGrabed", false);
}
}
}