Interaktionen 2.0

This commit is contained in:
Simon Lübeß
2024-04-07 00:09:53 +02:00
parent 2f5f25d0bd
commit dfe1451d3b
42 changed files with 1691 additions and 222 deletions

View File

@ -1,7 +1,12 @@
using System.Collections;
using System.Collections.Generic;
using Data;
using Interaction;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.Serialization;
using Utility;
public class Character : MonoBehaviour
{
@ -33,7 +38,20 @@ public class Character : MonoBehaviour
[Header("Hold item")]
[SerializeField] private Transform _hand;
[SerializeField] private GameObject _carriedItem;
[FormerlySerializedAs("_carriedItem")] [SerializeField] private GameObject _carriedItemModel;
[SerializeField] private PickupInteractible _carriedInteractible;
[FormerlySerializedAs("_throwAsideForce")] [SerializeField, Tooltip("Die Kraft mit der der Gegenstand fallen gelassen wird.")]
private float _dropItemForce = 3.0f;
[SerializeField]
private GottfriedData _data;
[SerializeField]
private AudioSource _audioSource;
public bool CarriesItem => _carriedInteractible;
public PickupInteractible CarriedItem => _carriedInteractible;
// Start is called before the first frame update
void Start()
@ -62,25 +80,24 @@ public class Character : MonoBehaviour
}
public void PickupItem(Pickupable itemToPickup)
public void PickupItem(PickupInteractible itemToPickup)
{
if (_carriedItem)
if (_carriedItemModel)
{
Pickupable pickupable = _carriedItem.GetComponentInChildren<Pickupable>(true);
pickupable.gameObject.SetActive(true);
pickupable.transform.parent = null;
_carriedInteractible.gameObject.SetActive(true);
_carriedInteractible.transform.parent = null;
pickupable.transform.position = _carriedItem.transform.position;
pickupable.transform.rotation = _carriedItem.transform.rotation;
_carriedInteractible.transform.position = _carriedItemModel.transform.position;
_carriedInteractible.transform.rotation = _carriedItemModel.transform.rotation;
Rigidbody rigidbody = pickupable.GetComponent<Rigidbody>();
Rigidbody rigidbody = _carriedInteractible.GetComponent<Rigidbody>();
rigidbody.AddForce(Random.insideUnitSphere * 2.0f, ForceMode.Impulse);
rigidbody.AddForce(Random.insideUnitSphere * _dropItemForce, ForceMode.Impulse);
Destroy(_carriedItem);
Destroy(_carriedItemModel);
_carriedItem = null;
_carriedItemModel = null;
_carriedInteractible = null;
}
if (itemToPickup)
@ -90,7 +107,7 @@ public class Character : MonoBehaviour
itemToPickup.transform.parent = model.transform;
itemToPickup.gameObject.SetActive(false);
_carriedItem = model;
_carriedInteractible = itemToPickup;
}
}
@ -149,4 +166,16 @@ public class Character : MonoBehaviour
{
readyToJump = true;
}
public void GiveItemTo(Developer developer)
{
Debug.Log($"Gebe {_carriedInteractible.Name} an {developer.Name}");
PickupItem(null);
}
public void SayItsImpossible()
{
_audioSource.PlayOneShot(_data.VoiceSayItsImpossible.GetRandomElement());
}
}