void OnCollisionEnter2D(Collision2D collidedWith) { carriable toCarry = collidedWith.gameObject.GetComponent<carriable>(); if(toCarry != null){ potentialCarriable = toCarry; } }
void OnCollisionExit2D(Collision2D leftCollision) { carriable toCarry = leftCollision.gameObject.GetComponent<carriable>(); if (toCarry != null) { potentialCarriable = null; } }
// Update is called once per frame void Update() { if (carryingThis != null) { carryingThis.transform.position = carryPoint.position; if (Input.GetButtonDown("Drop")) { carryingThis = null; } } else if (potentialCarriable != null) { if (Input.GetButtonDown("PickUp")) { carryingThis = potentialCarriable; potentialCarriable = null; } } }