This question was
closed Oct 13, 2015 at 07:05 PM by
hexagonius for the following reason:
No question has been asked
Question by
curleyjohnson · Oct 13, 2015 at 05:01 PM ·
collider2drespawn
I am making a 2d platform game. When I push a crate off screen, it collides with a hazard (as if it was the player) and causes a respawn. The crate is setup to collect coins that it comes into contact with. My Scripts are below, Thanks.
COIN SCRIPT
using UnityEngine;
namespace UnitySampleAssets._2D
{
public class coins : MonoBehaviour
{
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
coinController.screwCount++;
audio.Play();
Object.Destroy(gameObject, 0.1f);
}
if (other.tag == "Crate")
{
coinController.screwCount++;
audio.Play();
Object.Destroy(gameObject, 0.1f);
}
}
}
}
RESPAWN SCRIPT
using UnityEngine;
using System.Collections;
namespace UnitySampleAssets._2D
{
public class Restarter : MonoBehaviour
{
private void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
audio.Play ();
coinController.screwCount = 0;
StartCoroutine (DelayedLoad ());
}
private IEnumerator DelayedLoad()
{
yield return new WaitForSeconds (2.0f);
Application.LoadLevel (Application.loadedLevelName);
}
}
}
Comment