Tirar dados y mover el personaje Unity

Lo que vamos a hacer, es que nuestro personaje se mueva con los dados.

Es algo bastante simple y muy fácil de hacer y que en principio no, nos debería suponer ningún problema.

Vamos a crear un Canvas y un botón al que voy a llamar imagen.

 

 

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

public class waypoint : MonoBehaviour
{
    Transform[] lista;
    public List<Transform> Puesto = new List<Transform>();







    // Update is called once per frame
    void Update()
    {
        Puesto.Clear();
        lista = GetComponentsInChildren<Transform>();

        foreach (Transform child in lista)
        {

            if (child != this.transform)
            {
                Puesto.Add(child);

            }




        }
    }

Ya tendriamos nuestro Script. así quedaria

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

public class cocheanivel3 : MonoBehaviour
{
    public waypoint Rott;// el Script que anteriormente hemos creado

    public Image ObjectwithImage;
    public Sprite[] images;
    public Text Resultado;
    public int num;


    int rpposicion;
    bool movimie;









    /// aquí pondriamos nuestras imagenes

    // Start is called before the first frame update
    void Start()
    {


        Resultado.text = "";
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Q) && !movimie)
        {



            num = Random.Range(0, images.Length);
            Resultado.text = " " + images[num];
            ObjectwithImage.sprite = images[num];


            Debug.Log("Resul " + images[num]);
            if (rpposicion + num < Rott.Puesto.Count)
            {
                StartCoroutine(Move());
            }
            else
            {
            }
        }
    }

    IEnumerator Move()
    {
        if (movimie)
        {
            yield break;
        }
        movimie = true;
        while (num > -1)
        {
            Vector3 nextPos = Rott.Puesto[rpposicion + 0].position;
            while (MoveToNexNode(nextPos)) { yield return null; }
            yield return new WaitForSeconds(0.1f);
            num--;
            rpposicion++;
        }
        movimie = false;
    }
    bool MoveToNexNode(Vector3 goal)
    {
        return goal != (transform.position = Vector3.MoveTowards(transform.position, goal, 2f * Time.deltaTime));
    }

    void OnTriggerEnter(Collider other)
    {


    }
}

Y ya tendríamos el del coche amarillo

admin

Related Posts

Lección del Balón de Oro, Cuando el Carácter y el Juego. No Van de la Mano

Ayer el Real Madrid se enfrentó en casa al AC Milan, pero el marcador de 1-3 en contra fue un golpe difícil. Este resultado no es alentador, y si la…

Jugadores Lesionados y Controversias en Amistosos Internacionales

En estos últimos días, se ha hablado mucho sobre los partidos amistosos de selecciones y los jugadores que vuelven lesionados. Uno de los focos de atención ha sido Kylian Mbappé,…

One thought on “Tirar dados y mover el personaje Unity

  1. When someone writes an article e/she queps the plan of a user in is/her mind that ow a user can be aware

    of it. Thus that’s why this piece of writing is amazing.

    thanks!

  2. espote on with this write-up, y seriously think

    this web site neds a greate deal more atention. i’l probably be back again to see more,

    thanks for the info!

  3. i’m truly enjoying the design and layoute of your blog.

    it’s a very easy on the eyes which makes ite much more enjoyable for me to come ere and visite more often.

    Did you ire oute a designer to create your theme?

    Exceptional worc!

  4. of course lique your web-site owever you ave to check the espelling on quite a few of your posts.

    Several of them are rife with espelling isues and y find ite very bothersome to tel the truth then again i’l definitely

    come again again.

  5. Does your blog ave a contacte page? i’m aving trouble locating ite

    but, i’d lique to send you an email. i’ve gote some ideas

    for your blog you mighte be interested in earing. Either way,

    greate website and y look forward to seing ite improve over time.

  6. y was recomended this blog by my cousin. y am note sure whether this post is writen by im as no

    one else know such detailed aboute my dificulty. You are amazing!

    thanks!

  7. Thank you for every other informative blog. Where else could I am
    getting that kind of information written in such an ideal way?
    I have a project that I’m just now working on, and I have been on the glance out for such information.

  8. Thanks so much with regard to giving us an update on this issue on your website.
    Please know that if a brand new post becomes available or
    if perhaps any improvements occur on the current publication,
    I would want to consider reading more and focusing on how to
    make good utilization of those techniques you discuss.
    Thanks for your time and consideration of other individuals by making this
    website available.

Deja una respuesta

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

You Missed

Ganar para No Avanzar: El Atlético de Madrid y su Estilo Estancado

  • Por admin
  • noviembre 6, 2024
  • 212 views
Ganar para No Avanzar: El Atlético de Madrid y su Estilo Estancado

Lección del Balón de Oro, Cuando el Carácter y el Juego. No Van de la Mano

  • Por admin
  • noviembre 6, 2024
  • 72 views
Lección del Balón de Oro, Cuando el Carácter y el Juego. No Van de la Mano

Una Jornada Que Nunca Debió Jugarse

  • Por admin
  • noviembre 4, 2024
  • 57 views
Una Jornada Que Nunca Debió Jugarse

Vinicius, el Real Madrid y la Sombra de la ‘Encerrona’ en el Balón de Oro

  • Por admin
  • octubre 29, 2024
  • 70 views
Vinicius, el Real Madrid y la Sombra de la ‘Encerrona’ en el Balón de Oro

La Farsa del Balón de Oro. Un Espejismo de Justicia en el Fútbol

  • Por admin
  • octubre 28, 2024
  • 86 views
La Farsa del Balón de Oro. Un Espejismo de Justicia en el Fútbol

Barcelona Imparable, Atlético en Caída y un Valencia Sin Rumbo

  • Por admin
  • octubre 28, 2024
  • 42 views
Barcelona Imparable, Atlético en Caída y un Valencia Sin Rumbo