Started working on turrets
This commit is contained in:
75
Assets/Scripts/Interaction.cs
Normal file
75
Assets/Scripts/Interaction.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using StarterAssets;
|
||||
|
||||
public class Interaction : MonoBehaviour, IInteractable
|
||||
{
|
||||
[SerializeField] TextMeshProUGUI interactionPrompt;
|
||||
[SerializeField] float interactRange = 3f;
|
||||
StarterAssetsInputs starterAssetsInputs;
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
starterAssetsInputs = GetComponent<StarterAssetsInputs>();
|
||||
interactionPrompt.gameObject.SetActive(false);
|
||||
interactionPrompt.text ="";
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
RaycastHit hit;
|
||||
|
||||
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, interactRange))
|
||||
{
|
||||
IInteractable interactable = hit.transform.GetComponent<IInteractable>();
|
||||
if (interactable != null)
|
||||
{
|
||||
interactionPrompt.gameObject.SetActive(true);
|
||||
interactionPrompt.text = interactable.GetInteractionPrompt();
|
||||
//Debug.Log("Looking at interactable: " + hit.transform.name);
|
||||
if (!starterAssetsInputs.interact) return;
|
||||
{
|
||||
interactable.Interact(gameObject);
|
||||
interactionPrompt.gameObject.SetActive(false);
|
||||
starterAssetsInputs.InteractInput(false);
|
||||
}
|
||||
interactionPrompt.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
interactionPrompt.gameObject.SetActive(false);
|
||||
interactionPrompt.text = "";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
interactionPrompt.gameObject.SetActive(false);
|
||||
interactionPrompt.text = "";
|
||||
}
|
||||
}
|
||||
public void Interact(GameObject interactor)
|
||||
{
|
||||
Debug.Log("Interacted with " + gameObject.name);
|
||||
}
|
||||
|
||||
public bool CanInteract(GameObject interactor)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public string GetInteractionPrompt()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public void OnHighlight()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public void OnUnhighlight()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user