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

El Real Madrid remonta a la Roma, pero sigue sin convencer: ¿tiene Vinícius los días contados?

El Real Madrid remonta a la Roma, pero sigue sin convencer: ¿tiene Vinícius los días contados? Ayer el Real Madrid consiguió una victoria frente a la Roma en un partido…

El Barça está por encima de Messi, señor Gaspart, pero su historia más gloriosa lleva su nombre

JOAN GASPART a LEO MESSI Gaspart, Messi y el Barça: el club está por encima de todos, pero su historia no se puede borrar «¿Quién se ha creído? Que vaya…

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

El Real Madrid remonta a la Roma, pero sigue sin convencer: ¿tiene Vinícius los días contados?

  • Por admin
  • octubre 15, 2026
  • 17 views
El Real Madrid remonta a la Roma, pero sigue sin convencer: ¿tiene Vinícius los días contados?

El Barça está por encima de Messi, señor Gaspart, pero su historia más gloriosa lleva su nombre

  • Por admin
  • octubre 13, 2026
  • 17 views
El Barça está por encima de Messi, señor Gaspart, pero su historia más gloriosa lleva su nombre

Mbappé desafía al Bernabéu y Mourinho lo defiende: ¿castigo justo o caza mediática?

  • Por admin
  • octubre 10, 2026
  • 49 views
Mbappé desafía al Bernabéu y Mourinho lo defiende: ¿castigo justo o caza mediática?
El último baile del 10

Criticar a Lamine por su fútbol, sí; cuestionar que sea español, no.

  • Por admin
  • octubre 5, 2026
  • 53 views
Criticar a Lamine por su fútbol, sí; cuestionar que sea español, no.

Cristiano y Portugal: una historia demasiado grande para terminar de esta manera

  • Por admin
  • octubre 4, 2026
  • 23 views
Cristiano y Portugal: una historia demasiado grande para terminar de esta manera