Un juego facil de hacer

Aquí vamos aprender hacer un juego muy sencillo

El juego trataría unicamente de llevar la llave a su puerta y al llevar la llave a su puerta, una animación de un perro corriendo llegaría hasta la puerta el completar las 5 puertas habríamos terminado el nivel.

 

Aquí vemos como nuestra puerta ROSA no tiene ningún script ni siquiera un Box Collider, tiene un Tag con el nombre Rosa. Ahoraa vamos a ir con la llave

Aquí vemos como la llave tiene un Box Collider 2D y tiene su Tag «rosa» el mismo que tiene la llave. Su animación cuando la llave colisiones con la puerta.

Ahora os voy a poner el Script de la llave

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

public class ejemplo : MonoBehaviour
{
    public GameObject animacionPerro;

    public string Tag;
    public float closeVDidst = 0.05f;
    private Vector3 positionsss;
    private Vector3 offeset;
    float dist;
    GameObject GO;


    void Start()
    {

        GO = GameObject.FindGameObjectWithTag(Tag);


    }
    void OnMouseDown()
    {

        positionsss = Camera.main.WorldToScreenPoint(transform.position);
        offeset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, positionsss.z));

    }

    void OnMouseDrag()
    {

        Vector3 curseScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, positionsss.z);
        Vector3 curPosition = Camera.main.ScreenToWorldPoint(curseScreenPoint) + offeset;

        transform.position = curPosition;

        Vector3 partnerPos = Camera.main.WorldToViewportPoint(GO.transform.position);

        Vector3 myPos = Camera.main.WorldToViewportPoint(transform.position);

        dist = Vector2.Distance(partnerPos, myPos);

    }

    void OnMouseUp()
    {

        Cursor.visible = true;
        if (dist < closeVDidst)
        {
            transform.SetParent(GO.transform);

            animacionPerro.gameObject.SetActive(true);

            Conexiones.Instance.puntosdeljuego(1);
        }
    }
}

Ahora voy a poner el Script de mi animación para que se mueva de un lado a otro.

 

 

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

public class Movimientdog : MonoBehaviour
{
    public Transform pointToGo;
    public float speed;

    public bool colliding = false;

    private void Update()
    {
        if (!colliding)
        {
            //Move
            float step = speed * Time.deltaTime;
            transform.position = Vector2.MoveTowards(transform.position, pointToGo.position, step);
        }

    }

    //Callback when enter the trigger
    private void OnTriggerEnter2D(Collider2D collision)
    {
        colliding = true;

    }
}

 

Pagina del video: https://www.youtube.com/watch?v=ha6Oej6fjwo&t=330s

 

Related Posts

Mourinho ha vuelto, pero el Real Madrid no: muchas estrellas, demasiado ego y muy poco equipo

Mourinho y su segunda etapa en el Real Madrid: tengo muchas dudas La segunda etapa de Mourinho en el Real Madrid me genera muchas dudas. Yo soy de esas personas…

Lamine vs Kane: ganar el Mundial no significa haber sido el mejor

Hoy se enfrentan España e Inglaterra y, sinceramente, me parece un tanto ridículo e incluso algo injusto para otros futbolistas que sí tuvieron un papel protagonista en el Mundial que…

One thought on “Un juego facil de hacer”

  1. I was recommended this web site by means of my cousin. I am no
    longer certain whether this put up is written by means of him
    as nobody else understand such distinctive approximately my
    problem. You’re wonderful! Thank you!

  2. Woah! I’m really digging the template/theme
    of this website. It’s simple, yet effective. A lot of times it’s very difficult
    to get that «perfect balance» between user friendliness and visual appearance.
    I must say you have done a amazing job with this.
    Additionally, the blog loads very quick for me on Opera.
    Superb Blog!

Deja una respuesta

You Missed

Mourinho ha vuelto, pero el Real Madrid no: muchas estrellas, demasiado ego y muy poco equipo

  • Por admin
  • septiembre 26, 2026
  • 11 views
Mourinho ha vuelto, pero el Real Madrid no: muchas estrellas, demasiado ego y muy poco equipo

Lamine vs Kane: ganar el Mundial no significa haber sido el mejor

  • Por admin
  • septiembre 26, 2026
  • 19 views
Lamine vs Kane: ganar el Mundial no significa haber sido el mejor

Sí, quéjate del árbitro… pero primero juega al fútbol, el problema del Real Madrid va más allá del VAR.

  • Por admin
  • septiembre 22, 2026
  • 22 views
Sí, quéjate del árbitro… pero primero juega al fútbol, el problema del Real Madrid va más allá del VAR.

Raphinha tira del Barça, Lamine se lleva las portadas: ¿rendimiento o marketing?

  • Por admin
  • septiembre 20, 2026
  • 49 views
Raphinha tira del Barça, Lamine se lleva las portadas: ¿rendimiento o marketing?

Del Messi-Cristiano al “yo merezco el Balón de Oro”: ¿en qué momento cambió tanto el fútbol?

  • Por admin
  • septiembre 19, 2026
  • 38 views
Del Messi-Cristiano al “yo merezco el Balón de Oro”: ¿en qué momento cambió tanto el fútbol?

¿Libertad personal o falta de profesionalidad? El gesto de Vinícius, Mbappé y Konaté que divide opiniones

  • Por admin
  • septiembre 16, 2026
  • 36 views
¿Libertad personal o falta de profesionalidad? El gesto de Vinícius, Mbappé y Konaté que divide opiniones