Snippets

David Fraj Destruir un objeto del juego al caer, o al hacer click con explosion

Created by David Fraj
using UnityEngine;
using System.Collections;

public class Stone : MonoBehaviour {

	public GameObject explosion;

	//Creamos una variable, para establecer cuando la piedra morira
	private const float yDie=-30f;


	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		//Si la posicion y llega a ser menor que el valor donde debe morir, destruimos
		if(transform.position.y < yDie){
			//gameObject es el propio object asociado.
			Destroy (gameObject);
		}
	}

	void OnMouseDown(){
		Instantiate (explosion, transform.position, Quaternion.identity);
		//Cuando alguien pulsa sobre la piedra
		Destroy(gameObject);

	}


}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.