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();
|
||||
|
||||
43
3d Prototyp/Assets/Scripts/UiController.cs
Normal file
43
3d Prototyp/Assets/Scripts/UiController.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UiController : MonoBehaviour
|
||||
{
|
||||
[Header("Objects")]
|
||||
[SerializeField]
|
||||
private Pickupper _pickupper;
|
||||
|
||||
[Header("UI Elements")]
|
||||
[SerializeField]
|
||||
private GameObject _actionDisplay;
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _actionText;
|
||||
[SerializeField]
|
||||
private Button _prevActionButton;
|
||||
[SerializeField]
|
||||
private Button _nextActionButton;
|
||||
|
||||
void Update()
|
||||
{
|
||||
UpdateActionDisplay();
|
||||
}
|
||||
|
||||
private void UpdateActionDisplay()
|
||||
{
|
||||
bool show = _pickupper.PickupablesInRange.Count > 0;
|
||||
|
||||
_actionDisplay.SetActive(show);
|
||||
|
||||
if (!show)
|
||||
return;
|
||||
|
||||
_actionText.text = $"{_pickupper.Selected.Name}";
|
||||
|
||||
_prevActionButton.interactable = _pickupper.CanSelectPrevious;
|
||||
_nextActionButton.interactable = _pickupper.CanSelectNext;
|
||||
}
|
||||
}
|
||||
11
3d Prototyp/Assets/Scripts/UiController.cs.meta
Normal file
11
3d Prototyp/Assets/Scripts/UiController.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 06a2565e89388db4b965e2bd25be1ee5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user