• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by curleyjohnson · Oct 13, 2015 at 08:35 PM · collider2drespawning

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);
             }
         }
     }
 }
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Eugenius · Oct 13, 2015 at 09:34 PM 0
Share

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.

avatar image curleyjohnson Eugenius · Oct 13, 2015 at 11:12 PM 0
Share

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.

avatar image Eugenius · Oct 14, 2015 at 08:49 AM 0
Share

Let me check if I understand this correctly:

  1. $$anonymous$$ario-like game

  2. Player can collect coins

  3. 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?

avatar image curleyjohnson Eugenius · Oct 14, 2015 at 07:27 PM 0
Share

(B) is what I'm trying to accomplish. (A) is what's currently happening.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

31 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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 effect slow motion when collision with an object 2 Answers

(C#) Bullet Damage , OnCollisionTrigger2D not working,(C#) Bullet Damage, Trigger not working. 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges