- Home /
Question by
danieldixon123 · Mar 16, 2018 at 04:19 PM ·
clickkeycodeclick objects
Picking up an object and dropping it with the same keycode
I have a box in my scene which I can pick up by pressing E and dropping it by clicking the mouse. However I want to be able to click to pick the object up and click again to drop it.
void Update ()
{
if (Input.GetKeyDown (KeyCode.Mouse0)) {
if (Physics.Raycast (TransformCamera.position, TransformCamera.forward, out hit, 3f, RayMask)) {
if (hit.transform.tag == "PickableObject")
{
SetNewTransform (hit.transform);
}
}
}
if (Input.GetKeyDown (KeyCode.Mouse0))
{
RemoveTransform();
}
Does anybody know how I can do this?
Comment
Answer by ShadyProductions · Mar 16, 2018 at 04:22 PM
Just set a boolean
bool isSelected = false;
if (isSelected)
{
RemoveTransform();
isSelected = false;
}
else
{
SetNewTransform(hit.transform);
isSelected = true;
}
Your answer
Follow this Question
Related Questions
Quad Objects not responding to clicks. 1 Answer
Click on two objects to render third 2 Answers
How i do a clicker with moving objects? 1 Answer
click button and not show again 1 Answer
Change sprite images on button click 0 Answers