My player won't let go of the object
I'm very new to unity. I'm learning. And I'm trying to make items that the player can move around in a top-down, right-left space. My player so far can pick up the item, but it won't let go of the item. At first the player would fly off with the item, and it would be able to let go. But I removed the rigidbodies on the item so maybe it wouldn't fly off. But now the player can't let go. How do I make my player let go of the object?
This is my code.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class grabthings : MonoBehaviour { public Transform grabDetect; public Transform boxHolder; public float rayDist;
void Update()
{
RaycastHit2D grabCheck = Physics2D.Raycast(grabDetect.position, Vector2.right * transform.localScale, rayDist);
if(grabCheck.collider != null && grabCheck.collider.tag == "stick")
{
if(Input.GetKey(KeyCode.G))
{
grabCheck.collider.gameObject.transform.parent = boxHolder;
grabCheck.collider.gameObject.transform.position = boxHolder.position; //grabCheck.collider.gameObject.GetComponent()= true; } else { grabCheck.collider.gameObject.transform.parent= null; // grabCheck.collider.gameObject.GetComponent() = false;
}
}
}
}
Your answer
Follow this Question
Related Questions
I'm trying to create an object I can pick up and move in a 2D platformer. 0 Answers
Unity5 Script to pick up a object, and drop it does not work correctly. [Newbie] 0 Answers
Why Does My Cube Player rotate 180 degrees when I start My game? 2 Answers