Como coger objetos en Unity – [TUTORIAL PASO A PASO]

Aprende a agarrar objetos y a soltarlos donde quieras en este nuevo tutorial de Unity 3D!
Da igual si estas usando Unity 2017, Unity 2018 o Unity 2019, ya que es totalmente compatible con todos ellos!

No te pierdas ninguno de mis videos sobre creación de videojuegos en Unity y suscribete a mi canal!

1 comentario en “Como coger objetos en Unity – [TUTORIAL PASO A PASO]”

  1. Revisado cerca de 10 veces y no lo veo, aquí tienes los scripts por no puedes lo copie como comentario del video de Youtuve por si alguien mas podía ayudarme y tu no podias. Por si sirve de algo estoy usando la versión de Unity 2019.3.2f1.

    ===== El Scripts PickableObject =====

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PickableObject : MonoBehaviour
    {

    public bool isPickable = true;

    private void OnTriggerEnter(Collider other)
    {
    if (other.tag == «PlayerInteractionZone»)
    {
    other.GetComponentInParent().ObjectToPickUp = this.gameObject;
    }

    }

    private void OnTriggerExit(Collider other)
    {
    if (other.tag == «PlayerInteractionZone»)
    {
    other.GetComponentInParent().ObjectToPickUp = null;
    }
    }
    }

    ===== El Scritp PickUpObjects =====

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PickUpObjects : MonoBehaviour
    {

    public GameObject ObjectToPickUp;
    public GameObject PickedObject;
    public Tansform interactionZone;

    void Update()
    {
    if (ObjectToPickUp != null && ObjectToPickUp.GetComponent().isPickable == true && PickedObject == null)
    {
    if (Input.GetKeyDown(KeyCode.F))
    {
    PickedObject = ObjectToPickUp;
    PickedObject.GetComponent().isPickable = false;
    PickedObject.transform.SetParent(interactionZone);
    PickedObject.transform.position = interactionZone.position;
    PickedObject.GetComponent().useGravity = false;
    PickedObject.GetComponent().isKinematic = true;
    }
    }

    else if (PickedObject != null)
    {
    if (Input.GetKeyDown(KeyCode.F))
    {
    PickedObject.GetComponent().isPickable = true;
    PickedObject.transform.SetParent(null);
    PickedObject.GetComponent().useGravity = true;
    PickedObject.GetComponent().isKinematic = false;
    PickedObject = null;
    }
    }
    }
    }

    Muchas gracias, y perdona mi torpeza, me estas ayudando por partida doble en estos días de confinamiento.

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *