Pickup Pizza und so

This commit is contained in:
Simon Lübeß
2024-04-06 18:08:54 +02:00
parent 12b856e6e1
commit ba09d4fff1
59 changed files with 4956 additions and 93 deletions

View File

@ -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();