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 DomenicoToddy · May 11, 2016 at 07:08 AM · platformer

Problem with player dead and respawn

Hi guys! I'm making a 2d game for my exam's project but i have a problem. When the player touches the obstacle , he goes through him and not die , and consequently the checkpoint don't start. Anyone can help me? I've create 3 script for manage that. Here the code CHECKPOINT:

 public class Checkpoint : MonoBehaviour {
 
     public LevelManager levelManager;
     // Use this for initialization
     void Start () {
 
         levelManager = FindObjectOfType<LevelManager>();
 
     }
 
     // Update is called once per frame
     void Update () {
     
     }
 
     void onTriggerEnter2D(Collider2D other)
     {
         if (other.name == "Player")
         {
             levelManager.currentCheckpoint = gameObject;
             Debug.Log("Activated Checkpoint" + transform.position);
         }
     }

Here the code KILLPLAYER:

 public class KillPlayer : MonoBehaviour {
 
     public LevelManager levelManager;
 
     // Use this for initialization
     void Start () {
 
         levelManager = FindObjectOfType<LevelManager>();
 
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     void onTriggerEnter2D(Collider2D other)
     {
         if (other.name == "Player")
         {
             levelManager.RespawnPlayer();
         }
     }
 }
 

And here the code LEVELMANAGER: public GameObject currentCheckpoint;

 private PlayerController player;

 public GameObject deathParticle;
 public GameObject respawnParticle;

 // Use this for initialization
 void Start () {

     player = FindObjectOfType<PlayerController>();
 
 }
 
 // Update is called once per frame
 void Update () {
 
 }

 public void RespawnPlayer()
 {
     Instantiate(deathParticle, player.transform.position, player.transform.rotation);
     Debug.Log("Player Respawn");
     player.transform.position = currentCheckpoint.transform.position;
     Instantiate(respawnParticle, currentCheckpoint.transform.position, currentCheckpoint.transform.rotation);
 }

}

Also, i post pictures with object attributes. Thanks to anyone will help me! :) alt text

alt text

screenshot-2.png (159.3 kB)
screenshot-1.png (169.4 kB)
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Tyche10 · May 11, 2016 at 09:13 AM

I think the problem is that you do not have a rigidbody attached to one of the two colliding objects. Without a rigidbody in at least one, the trigger isn't activated. Does your player have a rigidbody attached? (The unity documentation about OnTriggerEnter2D doesn't say this explicitly, but the OnTriggerEnter documentation does, so I think this is the problem: http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerEnter.html) Edit: I just noticed that you spelled OnTriggerEnter2D wrong in both scripts. It should start with a capital O.

Comment
Add comment · Share
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
0

Answer by DomenicoToddy · May 11, 2016 at 09:16 AM

Yes, my player have attached the Rigidbody 2D

Comment
Add comment · Show 3 · Share
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 Tyche10 · May 11, 2016 at 09:18 AM 0
Share

I updated my answer. The problem is that you spelled the OnTriggerEnter2D function without a capital letter in the beginning, so unity doesn't recognize it.

avatar image DomenicoToddy · May 11, 2016 at 09:47 AM 0
Share

@Tyche10 omg! ahahah what a fail! it works, thank you so much! :)

avatar image Tyche10 DomenicoToddy · May 11, 2016 at 10:28 AM 0
Share

No problem ;) If you are satisfied by the answer you can accept it and close the question.

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

56 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 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

2D RigidBody slightly penetrates objects causing a bounce effect. 3 Answers

2d Plataform Player Walking on the Wall c# 0 Answers

Object sticks to the side of the collider 1 Answer

Attaching a gameObject above a rolling ball 1 Answer

How can I fix a null pointer exception? (2d platformer tutorial) 1 Answer


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