add shovel and digging, basic item interaction
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class BurriedItem : Diggable
|
||||
{
|
||||
public GameObject ItemToSpawn;
|
||||
public Transform Spawnpoint;
|
||||
|
||||
public override void Dig()
|
||||
{
|
||||
Instantiate(ItemToSpawn, Spawnpoint.position, Spawnpoint.rotation, null);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 086f0ec780ccd914cb5cdc02852d9254
|
||||
@@ -11,6 +11,9 @@ public class DialogueManager : MonoBehaviour
|
||||
public TextMeshProUGUI nameText;
|
||||
public TextMeshProUGUI dialogueText;
|
||||
|
||||
public TextMeshProUGUI itemText;
|
||||
public GameObject pickupHint;
|
||||
|
||||
public Animator animator;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
@@ -68,4 +71,16 @@ IEnumerator TypeSentence(string sentence)
|
||||
yield return new WaitForSeconds(0.01f);
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowItemText(string itemName)
|
||||
{
|
||||
itemText.text = itemName;
|
||||
pickupHint.SetActive(true);
|
||||
}
|
||||
|
||||
public void HideItemText()
|
||||
{
|
||||
itemText.text = "";
|
||||
pickupHint.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class Diggable : MonoBehaviour
|
||||
{
|
||||
public abstract void Dig();
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b927d0dd24f719438bf4d72abbab1fa
|
||||
@@ -0,0 +1,8 @@
|
||||
using UnityEngine;
|
||||
|
||||
// This is the actual ITEM data structure for keeping track of inventory/item actions
|
||||
public class Item : MonoBehaviour
|
||||
{
|
||||
public string itemName;
|
||||
public int id;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa43c795f1a58fa4785593558036d0b3
|
||||
@@ -0,0 +1,24 @@
|
||||
using UnityEngine;
|
||||
|
||||
// this class is specifically referring to items in the world that can be picked up
|
||||
public class PickupableItem : Interactable
|
||||
{
|
||||
public Item item;
|
||||
|
||||
public override void Interact()
|
||||
{
|
||||
Debug.Log("Picked up " + item.itemName + "!");
|
||||
MoveOutsideRange(); // I don't love this but if we destroy the object we probably need to do this first
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
public override void MoveInsideRange()
|
||||
{
|
||||
GameManager.Instance.DialogueManager.ShowItemText(item.itemName);
|
||||
}
|
||||
|
||||
public override void MoveOutsideRange()
|
||||
{
|
||||
GameManager.Instance.DialogueManager.HideItemText();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3bb397f7c2c8ee47bc71df7f8d491bf
|
||||
@@ -3,6 +3,7 @@
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
public GameObject DougBody;
|
||||
public Shovel Shovel;
|
||||
public float walkSpeed;
|
||||
|
||||
Interactable nearestInteractable;
|
||||
@@ -10,7 +11,7 @@ public class PlayerController : MonoBehaviour
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -19,6 +20,7 @@ void Update()
|
||||
RotatePlayerTowardMouse();
|
||||
Walk();
|
||||
TryInteract();
|
||||
DigDetector();
|
||||
}
|
||||
|
||||
void Walk()
|
||||
@@ -27,6 +29,14 @@ void Walk()
|
||||
transform.position += DougBody.transform.right * Input.GetAxis("Horizontal") * walkSpeed * Time.deltaTime;
|
||||
}
|
||||
|
||||
void DigDetector()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
Shovel.Dig();
|
||||
}
|
||||
}
|
||||
|
||||
void RotatePlayerTowardMouse()
|
||||
{
|
||||
Vector2 positionOnScreen = Camera.main.WorldToViewportPoint(DougBody.transform.position);
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Shovel : MonoBehaviour
|
||||
{
|
||||
public Animator shovelAnimator;
|
||||
|
||||
public void Dig()
|
||||
{
|
||||
shovelAnimator.SetTrigger("Dig");
|
||||
}
|
||||
|
||||
// this only works if this script is sitting on the object with the collider!!
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
Diggable diggable = other.GetComponent<Diggable>();
|
||||
if (diggable != null)
|
||||
{
|
||||
diggable.Dig();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21ea1f4973209f34aa1bfb2f1dda5454
|
||||
Reference in New Issue
Block a user