Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by largow · Apr 13, 2014 at 01:43 AM · 2dinstantiaterespawnfallingkill

Respawning player not working

Hello Guys, I'm making a 2D game , and I am having some trouble making my player respawn when he falls. I have a script attached to my player, that makes basically 3 things: Kill the player when he falls off a platform and touches an invisible Collider2D that detects the player, create a new one on the spawning point and then move the camera towards the new player.

But I can't get that going. Whenever my player dies, the camera moves towards the spawning point and I can see that a Character(Clone) is created, but I can't see him on the Game window (Only the camera moving if i move my player) and he appears visible on the Scene Window as well...

Here's the code:

 public class Respawn : MonoBehaviour {
 
     public GameObject character; //a prefab of my player will be attached to the script
     public Transform spawnPoint; // an empty gameObject will act as the spawnPoint
 
     void OnTriggerEnter2D(Collider2D coll){
         Destroy (coll.gameObject);
         if (character) {
             GameObject p = Instantiate (character, spawnPoint.position, Quaternion.identity) as GameObject;
             CamController cam = Camera.main.gameObject.GetComponent<CamController> (); //The script that mo
             cam.target = p.transform;            
         }
 
 
     }
 }

Hope you can help me!

Comment
Add comment · Show 2
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 getyour411 · Apr 13, 2014 at 01:47 AM 0
Share

FYI - you probably have other scripts that have Start/Awake GetComponent or drag/drop references to the player, but when you Destroy and then Respawn those are probably flaking out

avatar image glaucomorais · Apr 13, 2014 at 03:03 AM 0
Share

Why destroy player instance? Disable it, move it to the respawn and re-enable it. Unless you are making permanence for the corpse...

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by largow · Apr 14, 2014 at 03:16 AM

Fixed it! It was something related to the camera! Dont know why, just changed the camera projection I was using. Remember, this is 2D, never use perspective, you don't want depth and stuff like that. Use ORTOGRAPHIC. Also made a simpler script of my camera, I attach it if you want it:

Code:

using UnityEngine;

using System.Collections;

 public class CamaraController : MonoBehaviour {
  
     public Transform target;
     public float height = 3f;
     public float distance = 3f;
     public float damping = 5f;  
 
     // Update is called once per frame
 
     void Update () {
         Vector3 pos =  target.TransformPoint(0,height,-distance);
         transform.position = Vector3.Lerp (transform.position, pos, Time.deltaTime * damping);  
     }
 
 }
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 glaucomorais · Apr 13, 2014 at 03:15 AM

Destroy (coll.gameObject); at line 7.

Probably you're destroying the player when it is instantiated. Tag it and make sure to not destroy player when it collides with the gameobject that this script is attached.

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

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

22 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

Related Questions

Instantiate GameObject at Random time is not working 1 Answer

How do I make a clone of a prefab appear on the correct layer? [5.2.2f1] 1 Answer

Position + Vector3 doesn't return correct values 1 Answer

Issue with photon instantiate 0 Answers

2D Animation does not start 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