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 /
avatar image
0
Question by Luckyy122 · Jun 24, 2016 at 05:01 AM · collisionreload

Reload level on collision

I have spent the last 4 hours trying to figure this out with no luck: I'm trying to get the Player (who is a box) to respawn at a set point immediately after coming in contact with the enemy (who is another box). What do i do?

Comment
Add comment · Show 1
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 NoseKills · Jun 24, 2016 at 07:31 AM 0
Share

What have you tried? What didn't work? Show us your code and we might be able to tell what's wrong in it.

3 Replies

· Add your reply
  • Sort: 
avatar image
-1
Best Answer

Answer by Luckyy122 · Jun 24, 2016 at 12:14 PM

I fixed it. Here's the code:

using UnityEngine; using System.Collections;

public class respawn : MonoBehaviour { private object cube;

 void OnCollisionEnter(Collision col)
 {
     if (col.gameObject.name == "Player")
     {
         Application.LoadLevel(Application.loadedLevel);
     }

 }

} }

 }
Comment
Add comment · Show 2 · 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 YoungDeveloper · Jun 24, 2016 at 01:07 PM 1
Share

Ter$$anonymous$$ology Respawn means repositions the player, but you are Realoding the $$anonymous$$ap, that's what Application LoadLevel does, it's not the same thing.

avatar image EpiFouloux · Jun 24, 2016 at 01:35 PM 0
Share

wow that's NOT a solution man, check $$anonymous$$e ins$$anonymous$$d

avatar image
1

Answer by YoungDeveloper · Jun 24, 2016 at 09:14 AM

Wow, 4 hours, that's really a lot of time.

But, to help your problem. What is spawn? It's basically a movement to certain position (teleport effect), or an actual new player creation. You move your player back to your position using its transform.position = ... or use Instantiate for an actual new creation.

Comment
Add comment · Show 1 · 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 Luckyy122 · Jun 29, 2016 at 12:36 PM 0
Share

I would like spawn to be when the player teleports to a location after touching the enemy

avatar image
0

Answer by EpiFouloux · Jun 24, 2016 at 09:56 AM

Save the position on your start function :

 [RequireComponent(typeof(Collider))]
 public class Player : MonoBehaviour
 {
      private Vector3 original_pos;
 
      void Start()
      {
            original_pos = transform.position;
      }

      public void reset_position()
      {
            transform.position = original_pos;
      }

      void OnCollisionEnter(Collision coll)
      {
            if (coll.gameObject.tag == "enemy")
            {
                  reset_position();
            }
      }
 }

Comment
Add comment · Show 1 · 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 EpiFouloux · Jun 24, 2016 at 09:58 AM 0
Share

and if you want a specific position, set orignal_pos as a public variable or as a Serialized Transform

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

7 People are following this question.

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

Related Questions

2D Platformer Reload Game On Collision With Sprite 1 Answer

Nav Mesh Agent won't fall off the platform? 1 Answer

Creating and removing HUDs on Collision 1 Answer

Display a different sprite each reload in the game 0 Answers

How can I stop a rigidbody (Ragdoll) character from colliding with the Character Controller capsule? 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