Pickup Pizza und so
This commit is contained in:
@ -31,6 +31,10 @@ public class Character : MonoBehaviour
|
||||
public LayerMask whatIsGround;
|
||||
public bool grounded;
|
||||
|
||||
[Header("Hold item")]
|
||||
[SerializeField] private Transform _hand;
|
||||
[SerializeField] private GameObject _carriedItem;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
@ -58,6 +62,38 @@ public class Character : MonoBehaviour
|
||||
|
||||
}
|
||||
|
||||
public void PickupItem(Pickupable itemToPickup)
|
||||
{
|
||||
if (_carriedItem)
|
||||
{
|
||||
Pickupable pickupable = _carriedItem.GetComponentInChildren<Pickupable>(true);
|
||||
|
||||
pickupable.gameObject.SetActive(true);
|
||||
pickupable.transform.parent = null;
|
||||
|
||||
pickupable.transform.position = _carriedItem.transform.position;
|
||||
pickupable.transform.rotation = _carriedItem.transform.rotation;
|
||||
|
||||
Rigidbody rigidbody = pickupable.GetComponent<Rigidbody>();
|
||||
|
||||
rigidbody.AddForce(Random.insideUnitSphere * 2.0f, ForceMode.Impulse);
|
||||
|
||||
Destroy(_carriedItem);
|
||||
|
||||
_carriedItem = null;
|
||||
}
|
||||
|
||||
if (itemToPickup)
|
||||
{
|
||||
GameObject model = Instantiate(itemToPickup.Model, _hand);
|
||||
|
||||
itemToPickup.transform.parent = model.transform;
|
||||
itemToPickup.gameObject.SetActive(false);
|
||||
|
||||
_carriedItem = model;
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
MovePlayer();
|
||||
|
||||
Reference in New Issue
Block a user