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

    El fútbol femenino español lo tiene todo menos una gran audiencia: ¿qué está fallando?

    El fútbol femenino español tiene motivos para sentirse orgulloso, pero necesita seguir creciendo Para mí, el fútbol femenino español es algo de lo que podemos sentirnos profundamente orgullosos. Tenemos una…

    La paradoja del fútbol español: el Barcelona juega con más españoles que el Real Madrid

    El Barcelona se españoliza cada vez más, La Masía ahora Rodri refuerzan una identidad muy nacional Con el fichaje de Rodri, el Barcelona continúa aumentando el peso de los futbolistas…

    Deja una respuesta

    You Missed

    El fútbol femenino español lo tiene todo menos una gran audiencia: ¿qué está fallando?

    • Por admin
    • agosto 19, 2026
    • 10 views
    El fútbol femenino español lo tiene todo menos una gran audiencia: ¿qué está fallando?

    La paradoja del fútbol español: el Barcelona juega con más españoles que el Real Madrid

    • Por admin
    • agosto 18, 2026
    • 10 views
    La paradoja del fútbol español: el Barcelona juega con más españoles que el Real Madrid

    Rodri por 60 millones y con 30 años: ¿fichajazo del Barcelona o demasiado riesgo?

    • Por admin
    • agosto 18, 2026
    • 9 views
    Rodri por 60 millones y con 30 años: ¿fichajazo del Barcelona o demasiado riesgo?

    Ferran Torres ficha por el PSG: ¿se arrepentirá el Barcelona de su salida?

    • Por admin
    • agosto 15, 2026
    • 23 views
    Ferran Torres ficha por el PSG: ¿se arrepentirá el Barcelona de su salida?

    LaLiga 2026-27: Real Madrid, Barcelona y Atlético luchan por el título

    • Por admin
    • agosto 15, 2026
    • 22 views
    LaLiga 2026-27: Real Madrid, Barcelona y Atlético luchan por el título

    Ferran al PSG: una cosa son los colores y otra muy distinta el dinero

    • Por admin
    • agosto 15, 2026
    • 28 views
    Ferran al PSG: una cosa son los colores y otra muy distinta el dinero