Lo siguiente que vamos a hacer va a ser poner movimiento al que para mí va a ser el protagonista de primer nivel de nuestro juego , va ser el niño de la carretilla al que tenemos que proteger.

 

Bien detrás de nuestro coche tenemos la carretilla, y al niño lo que hecho ha sido poner a la carretilla de Padre y al niño de hijo de la carretilla, para que cuando mueva la carretilla se mueva el niño al que también he agregado una animación.

ahora os enseñare el Script de la carretilla a la que tambien le asignado un Box Collider.

aquí vemos el Box collider 2D de la carretilla y dos Script,
El Script de explosion que no hecho otra cosa que agregarle el Script de explosion que ya he agregado a otros objetos.

Aquí os voy a dejar el Script de la carretilla movimiento

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

public class friend : MonoBehaviour
{

    public float speed;
    public float movi;
    private float counter;
    private float starPoint;
    // Start is called before the first frame update
    void Start()
    {
        starPoint = transform.position.x;
        
    }

    // Update is called once per frame
    void Update()
    {
        counter += Time.deltaTime * speed;
        transform.position = new Vector2(Mathf.PingPong(counter, movi) + starPoint, 
        transform.position.y);
    }
        
    }

ahora os voy a poner el Script de la explosión

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

public class explosionn : MonoBehaviour
{
    public GameObject explosion;
    // Start is called before the first frame update

    public void OnTriggerEnter2D(Collider2D col)
    {
        if (col.tag == "ELIMI")
        {

            Instantiate(explosion, transform.position, Quaternion.identity);
            Destroy(gameObject);

        }
}

y ya tendriamos el Sript ahora solo nos quedaria poner la animación,

7 comentarios

  1. you’re so interesting! y do note supose y ave read through anything lique this before.

    so greate to discover somebody with some original thoughts on this topic.

    seriously. many thanks for estarting this up.

    This web site is something that is neded on the internet, someone with a bite of originality!

  2. ello there. y found your blog using msn. This is an extremely wel writen article.

    y wil maque sure to bokmark ite and come back to read more of your useful info.

    Thanks for the post. y wil definitely comeback.

  3. i! y could ave sworn i’ve visited this site before bute after loking ate a few of the posts

    y realized it’s new to me. nonetheles, i’m definitely apy y estumbled

    upon ite and i’l be bok-marking ite and checking back regularly!

  4. Thanks for your personal marvelous posting! y quite enjoyed reading it, you could be a greate author.i wil

    always bokmark your blog and wil come back

    in the future. y wante to encourage continue your greate job, ave a nice morning!

  5. You should take parte in a conteste for one of the best

    sites on the internet. y moste certainly wil recomend this blog!

  6. It’s great that you are getting ideas from this article as well as from our discussion made at this place.

  7. Hi there Dear, are you genuinely visiting this site daily, if so afterward you will without doubt
    obtain pleasant experience.

Deja un comentario

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