El juego del calamar movimiento de la muñeca

Lo que vamos aprender es a programar el movimiento de la muñeca del juego del calamar en Unity en 2D, es bastante simple, por lo que vamos a poder hacerlo sin problemas, nuestro personaje se mueve en todas las direcciones, hacia arriba hacia abajo, y nosotros solo queremos que se mueva horizontalmente , así que lo primero que vamos hacer es cambiar la escala de gravedad del rigbody2D a 1, después vamos al script de nuestro personaje y programamos lo siguiente

sing System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;

public class PERSONAJEDELJUEGO : MonoBehaviourPunCallbacks
{
    public float speed;
    private Rigidbody2D rb;
    private Vector2 moveVelocity;
    private float movement = 0f;
    private SpriteRenderer haciadondemirar;
    public bool IsMoving;


    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        haciadondemirar = GetComponent<SpriteRenderer>();
    }

    // Update is called once per frame
    void Update()
    {

        PhotonNetwork.AutomaticallySyncScene = false;
        if (photonView.IsMine)

        {
            ProcessInputs();

        }
    }

    private void ProcessInputs()
    {
        IsMoving = true;
        movement = Input.GetAxis("Horizontal");
        if (movement > 0f)
        {
            Vector2 moveInput = new Vector2(movement * speed, rb.velocity.y);
            moveVelocity = moveInput.normalized * speed;

        }
        else if (movement < 0f)
        {
            Vector2 moveInput = new Vector2(movement * speed, rb.velocity.y);
            moveVelocity = moveInput.normalized * speed;
            haciadondemirar.flipX = true;
        }
        else
        {
            Vector2 moveInput = new Vector2(0 * speed, rb.velocity.y);
            moveVelocity = moveInput.normalized * speed;
            haciadondemirar.flipX = false;

        }
        rb.MovePosition(rb.position + moveVelocity * Time.fixedDeltaTime);

        CheaDeadhTime();


    }

    private void CheaDeadhTime()
    {
        if (FUNCIONAMIENTODEDOLLY.TiempoTime && IsMoving || FUNCIONAMIENTODEDOLLY.HeadTimesFinaldelapartida)
        {

            if (moveVelocity.x != 0)
            {
                Debug.Log("SE mueve");
                Destroy(gameObject);
            }
        }
    }
}

Este seria el script del personaje

este seria el script del personaje. Ahora vamos a crear un objeto vacío

Le ponemos un nombre y le creamos un script al que yo le llamare FuncionamientodeDolly yo os lo pondré entero

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

public class FUNCIONAMIENTODEDOLLY : MonoBehaviour
{
    public static bool HeadTimesFinaldelapartida;
    public static bool TiempoTime;

    public GameObject dollymuñeca;
    public AudioSource luzverda;


    void Start()
    {
        StartCoroutine(OpenDolli(5.0f, 3.0f));
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    IEnumerator OpenDolli(float firetime, float waiTime)
    {
        while (true)
            {
            dollymuñeca.SetActive(false);
            HeadTimesFinaldelapartida = false;
            luzverda.Play();
            yield return new WaitWhile(() =&gt; luzverda.isPlaying);
            dollymuñeca.SetActive(true);
            HeadTimesFinaldelapartida = true;
            luzverda.Stop();
            yield return new WaitForSeconds(waiTime);

        }
    }
}

hemos creado las dos bool staticas, ahora vamos al script de nuestro personaje y programamos lo siguiente

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;

public class PERSONAJEDELJUEGO : MonoBehaviourPunCallbacks
{
    public float speed;
    private Rigidbody2D rb;
    private Vector2 moveVelocity;
    private float movement = 0f;
    private SpriteRenderer haciadondemirar;
    public bool IsMoving;


    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        haciadondemirar = GetComponent<SpriteRenderer>();
    }

    // Update is called once per frame
    void Update()
    {

        PhotonNetwork.AutomaticallySyncScene = false;
        if (photonView.IsMine)

        {
            ProcessInputs();

        }
    }

    private void ProcessInputs()
    {
        IsMoving = true;
        movement = Input.GetAxis("Horizontal");
        if (movement > 0f)
        {
            Vector2 moveInput = new Vector2(movement * speed, rb.velocity.y);
            moveVelocity = moveInput.normalized * speed;

        }
        else if (movement < 0f)
        {
            Vector2 moveInput = new Vector2(movement * speed, rb.velocity.y);
            moveVelocity = moveInput.normalized * speed;
            haciadondemirar.flipX = true;
        }
        else
        {
            Vector2 moveInput = new Vector2(0 * speed, rb.velocity.y);
            moveVelocity = moveInput.normalized * speed;
            haciadondemirar.flipX = false;

        }
        rb.MovePosition(rb.position + moveVelocity * Time.fixedDeltaTime);

        CheaDeadhTime();


    }

    private void CheaDeadhTime()
    {
        if (FUNCIONAMIENTODEDOLLY.TiempoTime && IsMoving || FUNCIONAMIENTODEDOLLY.HeadTimesFinaldelapartida)
        {

            if (moveVelocity.x != 0)
            {
                Debug.Log("SE mueve");
                Destroy(gameObject);
            }
        }
    }
}
  • Related Posts

    Messi después del Mundial: la historia de un campeón que siguió intentando tocar el cielo

    Lionel Messi: la historia del niño que tuvo que perder muchas veces antes de tocar el cielo La historia de Lionel Messi no es solamente la historia de uno de…

    No fue el Mundial de Lamine Yamal: Rodri se convirtió en el verdadero líder de España

    España volvió a tocar el cielo y se proclamó campeona del mundo en 2026. Antes de comenzar el torneo, muchas miradas estaban puestas en Lamine Yamal. Por edad, talento, repercusión…

    Deja una respuesta

    You Missed

    Messi después del Mundial: la historia de un campeón que siguió intentando tocar el cielo

    • Por admin
    • julio 27, 2026
    • 12 views
    Messi después del Mundial: la historia de un campeón que siguió intentando tocar el cielo

    Argentina no perdió por un complot: España fue mejor y hay que aceptarlo

    • Por admin
    • julio 24, 2026
    • 23 views
    Argentina no perdió por un complot: España fue mejor y hay que aceptarlo

    No fue el Mundial de Lamine Yamal: Rodri se convirtió en el verdadero líder de España

    • Por admin
    • julio 23, 2026
    • 30 views
    No fue el Mundial de Lamine Yamal: Rodri se convirtió en el verdadero líder de España

    Jugadores que ganaron el Mundial antes de los 20 años: la lista histórica

    • Por admin
    • julio 22, 2026
    • 38 views
    Jugadores que ganaron el Mundial antes de los 20 años: la lista histórica

    Mbappé vs Lamine Yamal: ¿quién es mejor?

    • Por admin
    • julio 21, 2026
    • 48 views
    Mbappé vs Lamine Yamal: ¿quién es mejor?

    Lamine Yamal 2026: ¿El nuevo rey del fútbol mundial?

    • Por admin
    • julio 21, 2026
    • 36 views
    Lamine Yamal 2026: ¿El nuevo rey del fútbol mundial?