Hello, I am new to coding and would like some help with how I can edit this code. I was doing a tutorial and I wanted to edit it. I want the player to be able to press E to pick up the object and then also put it down by pressing E again.
Right now you can press E to pick it up and then right click on mouse to drop it.
void Update()
{
//check distance of gameObject and player
float dist = Vector3.Distance(gameObject.transform.position, player.position);
if (dist <= 4.5f)
{
//can be picked up
hasPlayer = true;
}
else
{
hasPlayer = false;
}
if (hasPlayer && Input.GetButtonDown("Use"))
{
GetComponent<Rigidbody>().isKinematic = true;
transform.parent = p_Camera;
beingCarried = true;
}
if (beingCarried)
{
if (touched)
{
GetComponent<Rigidbody>().isKinematic = false;
transform.parent = null;
beingCarried = false;
touched = false;
}
if (Input.GetMouseButtonDown(0))
{
GetComponent<Rigidbody>().isKinematic = false;
transform.parent = null;
beingCarried = false;
GetComponent<Rigidbody>().AddForce(p_Camera.forward * throwForce);
}
//right mouse button
else if (Input.GetMouseButtonDown(1))
{
GetComponent<Rigidbody>().isKinematic = false;
transform.parent = null;
beingCarried = false;
}
}
}
void OnTriggerEnter()
{
if (beingCarried)
{
touched = true;
}
}
}
I’m guessing I have to make “else if (Input.GetMouseButtonDown(1))” to “Input.GetButtonDown(“Use”)” but I’m not sure what to do for " (Input.GetMouseButtonDown(0))." Any help would be appreciated.