I am trying to pick up an object and spawn it to an empty gameobject in front of my player,
but its not working
it doesnt even show the print in the console
{
private bool isHolding;
public GameObject spawnTo;
RaycastHit hit;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void FixedUpdate()
{
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast(this.transform.position, transform.forward, out hit, 5.0f))
{
if (hit.collider.tag == "Moveable" && isHolding == false)
{
print("hit moveable object");
//hit.transform.gameObject.transform.position = spawnTo.transform.position;
hit.transform.gameObject.transform.parent = spawnTo.gameObject.transform;
hit.transform.gameObject.GetComponent<Rigidbody>().isKinematic = false;
isHolding = true;
// spawnTo
}
}
Debug.DrawRay(this.transform.position, transform.forward*5.0f, Color.red);
if (Input.GetMouseButtonDown(0) && isHolding == true)
{
hit.transform.gameObject.transform.parent = null;
hit.transform.gameObject.GetComponent<Rigidbody>().isKinematic = true;
isHolding = false;
}
}
}
}
i could pick them up if i changed the second mousebuttondown to mousebuttonUp but i couldnt release it, and after a while the cube just dissapeared.
my console still didnt print it though.
thanks in advance