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);
            }
        }
    }
}

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *