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 bula · Dec 05, 2011 at 12:50 AM · spawn

Make a spawn point

I want to make a spawn point for my character. A function that will make him spawn when he dies and something else when the level is won How can i do something like this? Please HELP!

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

1 Reply

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

Answer by ByteSheep · Dec 05, 2011 at 04:01 AM

To make a spawn point just create an empty game object and position it where you want your player to be spawned. You then need to add a script to the player that sets the variable "respawn"(can be called anything) to true when his life points are down to zero. I don't really know how you're determining wether the player has died, but I am assuming you used life points.. It could look something like this:

 var SpawnPoint : Transform;
 var respawn : boolean = false;
 var PlayerLife : int;
 
 function Update () {
 
    if(PlayerLife <= 0)
    {
    respawn = true;
    }
    else
    {
    respawn = false;
    }
 
     if(respawn)
     {
 
     transform.position = SpawnPoint.position;
 
     }
 }

You will have to add the game object you created before (spawn point) to the slot called "SpawnPoint" in the inspector window. This is a very basic script that will send your player to the position of the respawn point as soon as his life points reach zero. This should help you get a simple respawn which you can customise to your needs, hope it helped!

Comment
Add comment · Show 5 · 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 bula · Dec 05, 2011 at 03:30 PM 0
Share

Cheers mate but tell me something...inspector window is this line of the code? transform.position = SpawnPoint.position; So I have to add (lets say the cube to this line?)How do i do this?(i'm really low but i hope i'm gonna learn) Ty very much for making this script. Hope you can answer my question if it's not to dumb. Ty

avatar image ByteSheep · Dec 05, 2011 at 06:40 PM 0
Share

The inspector window is not part of the code but is ins$$anonymous$$d a part of the unity layout - you have game/scene view, your project, your hierarchy, and then your Inspector. The Inspector is normally situated on the right of the unity layout I think. All 'parts' of the interface are labeled though: hierarchy, inspector etc. When you click on your player (player should be in the hierarchy), then the Inspector should show you the script component.. That is where you should see a slot named Spawn Point and that is where you can drag the spawn point game object. So to sum up: Click on your player in the hierarchy section and then look at the inspector (should be on right side), if the player has not got the script attached yet then you'll have to drag the script (above) into the inspector - which should create a script component in the inspector. That script component should have a 'slot' named Spawn Point where you can select (or drag) a game object from your hierarchy section, in this case needing to be your spawn point game object. Here's an image of the inspector, hierarchy and project section: http://www.scriptocalypse.com/wp-content/uploads/2011/10/unityEditorScriptSample2_3.png Hope it helped understand it!

avatar image bula · Dec 05, 2011 at 06:52 PM 0
Share

Cheers mate:) It did

avatar image ArturoTGN · Feb 13, 2019 at 12:25 AM 1
Share

Is this C# or JavaScript? I'm trying to implement the code using C#.

avatar image bakerm8 · Dec 04, 2019 at 08:06 PM 0
Share

Okay, @ByteSheep ,but how would be written if you need to respawn after touching something?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Spawning script error 0 Answers

Why Does My GameObject Not Spawn Anymore? 2 Answers

Spawning objects help 2 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