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 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…

    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
    • 19 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
    • 18 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
    • 50 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