Exemple #1
0
    public void Interact(GameObject player)
    {
        // Get player game object
        PlayerInventory inv = player.GetComponent <PlayerInventory>();

        if (inv)
        {
            if (inv.objects.Count < 5)
            {
                bool success = inv.AddObject(this);
                if (success)
                {
                    gameObject.SetActive(false);
                }
                else
                {
                    Debug.Log("Inventory Full");
                }
            }
        }
    }
Exemple #2
0
    void Update()
    {
        ray.origin    = Camera.main.gameObject.transform.position;
        ray.direction = Camera.main.gameObject.transform.forward;

        if (Physics.Raycast(ray, out hit, interactionMinDistance))
        {
            if (hit.collider.gameObject.GetComponent <InteractableObject>() != null)
            {
                if (currentInteractable != null)
                {
                    if (hit.collider.gameObject.GetComponent <InteractableObject>() != currentInteractable)
                    {
                        currentInteractable.SetShaderFloat(0);
                    }
                }
                currentInteractable = hit.collider.gameObject.GetComponent <InteractableObject>();
                currentInteractable.SetShaderFloat(HighlightedLineWidth);
                currentInteractable.SetShaderColor(lineColor);

                if (Input.GetKey(KeyCode.E))
                {
                    playerInventory.AddObject(hit.collider.gameObject);
                    currentInteractable.SetShaderFloat(0);
                }
            }
            else if (currentInteractable != null)
            {
                currentInteractable.SetShaderFloat(0);
                currentInteractable = null;
            }
        }
        else if (currentInteractable != null)
        {
            currentInteractable.SetShaderFloat(0);
            currentInteractable = null;
        }
    }