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 hizo un Mundial increíble con 39 años, pero para mí no merece el Balón de Oro 2026.

    Messi y el Balón de Oro 2026 un Mundial increíble a los 39 años, pero para mí no es suficiente Hablar de Lionel Messi y el Balón de Oro, creo…

    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…

    Deja una respuesta

    You Missed

    Messi hizo un Mundial increíble con 39 años, pero para mí no merece el Balón de Oro 2026.

    • Por admin
    • septiembre 29, 2026
    • 5 views
    Messi hizo un Mundial increíble con 39 años, pero para mí no merece el Balón de Oro 2026.

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

    • Por admin
    • septiembre 26, 2026
    • 13 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
    • 22 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
    • 24 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
    • 39 views
    Del Messi-Cristiano al “yo merezco el Balón de Oro”: ¿en qué momento cambió tanto el fútbol?