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
1
Question by Sugar Mommy · Jun 17, 2015 at 10:45 PM · 2dspriteplatformerspriterenderersorting layers

[2D] [C#] Sprite disappears after changing position

I've run into a problem that's been bothering me a little bit. I'm sure the cause of it is something very simple, but I can't seem to think of anything.

My scene currently has a set of spikes and a player. Whenever the player collides with the spikes, it's supposed to respawn at a checkpoint. I've used the following scripts for this:


KillPlayer (attached to Spikes)

 public LevelManager levelManager;
 
     void Start () 
     {
         levelManager = FindObjectOfType<LevelManager>();
     }
 
     void OnTriggerEnter2D(Collider2D other)
     {
         if (other.name == "player")
         {
             levelManager.RespawnPlayer();
         }
     }



LevelManager (attached to empty gameobject in scene)

  public GameObject currentCheckpoint;
     private PlayerController player;
 
     void Start () 
     {
         player = FindObjectOfType<PlayerController>();
     }
 
     public void RespawnPlayer()
     {
         Debug.Log("Player respawned.");
         player.transform.position = currentCheckpoint.transform.position;
     }



I know this script works, because when I move the player into the spikes, the camera moves back to the position of the checkpoint. However, after this happens, I can't see my player anymore.

After some research I found that the problem might have something to do with the Sprite Renderer's Sorting Layer being set on default, but I'm too much of a newbie to know what I'm supposed to change to fix this.

To be sure, here's a few screenshots.

alt text alt text

Comment
Add comment · Show 3
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 Ricna · Jun 18, 2015 at 02:13 AM 0
Share

Probably is a simple issue with axis or rotation when you respawn the player. I didn't understand you question exactly, but for sure you need do keep your player "alive", just enable and disable, changing the position to the previous checkpoint. $$anonymous$$aybe you can create a Singleton in this case if you are changing the scene too.

avatar image digzou · Jun 18, 2015 at 09:36 AM 0
Share

Check the 'Z' of the transform o your camera and 'disappearing_gameObject' before and after doing the your update in game. The case should be that the z value of either of those gameobjects is changing.

avatar image Sugar Mommy · Jun 18, 2015 at 01:15 PM 0
Share

Yep, looks like it was the Z-axis being wrong after all. Thank you very much for your answers!

1 Reply

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

Answer by komodor · Jun 18, 2015 at 10:09 AM

 player.transform.position = new Vector3(currentCheckpoint.transform.position.x, currentCheckpoint.transform.position.y, player.transform.position.z);
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

23 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

Related Questions

Pixels from a sprite aren't the same size 0 Answers

Sprite cutoff/altered in game view but not scene view 0 Answers

Texturing custom 2d sprite 0 Answers

Disabled sprite renderer's briefly show on level load 2 Answers

How to truncate sprite without changing the scale of the sprite? 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