Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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.

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 check if a collider is Touching any other object 2 Answers

Unity3d tutorial angry meteor issues with circlecollider2D in unity5 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges