2d platform game. When I push a crate off screen, it collides with a hazard and causes the player to respawn. The crate is setup to collect coins, thats it. How do I stop the crate from causing my player to respawn?
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);
}
}
}
Coins 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);
}
}
}
}
Well, you're actually calling this Application.LoadLevel in your Respawn script, which means your level gets loaded again.
I'm not sure what you're trying to achieve but if you don't need the level to be reloaded - don't use Application.LoadLevel.
Hi Eugenius, thanks for responding to my post. I'm making a $$anonymous$$ario like game. The player can collect coins and if the crate slides, it will also collect the coins it comes in contact with. The LoadLevel is for respawning the player. But when the crate goes off-screen it causes the player to respawn.
Let me check if I understand this correctly:
$$anonymous$$ario-like game
Player can collect coins
Crate is not the player but something that the player pushes
Next is where I don't really understand, is it:
a. If the crate slides off, the game is lost & player must respawn? b. If the crate slides off, the game isn't lost & the player shouldn't respawn?
(B) is what I'm trying to accomplish. (A) is what's currently happening.
Your answer
Follow this Question
Related Questions
Getting nullReferenceException when respawning a gameObject and trying to access the audio source. 0 Answers
I can't get player to respawn over network. 1 Answer
Ragdoll death respawn help 0 Answers
How to check if a collider is Touching any other object 2 Answers
Unity3d tutorial angry meteor issues with circlecollider2D in unity5 0 Answers