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 xToxicInferno · Feb 27, 2010 at 09:24 PM · transformpositionrespawnsyntax

Respawn question

I am trying to make a game, where if you walk into a certain point (pre-defined with a trigger collider) and it will set that location as your next spawn point if you were to die.

My idea for this to work was to have have a collider with Is Trigger selected, place it around the area i want, then tag it as Marker1 (as i am just testing this to get it to work) and have it so if it is Marker1 it will overwrite the default spawn point with that one. I got all that to work, but i do not know the correct syntax of the code i am trying to write.

I am trying to write:

transform.position = GameObject.Find(spawnpoint).transform.position;

Though this is the wrong syntax. Also 'spawnpoint' would be a string. I would attach this to the player, so it would set the players position the the position of whatever spawnpoint is. So please help me out...

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
2
Best Answer

Answer by Murcho · Feb 27, 2010 at 11:10 PM

You would probably be best off having a script that tracks where the player should respawn. It should hold a reference to the current respawn transform, and that reference should be updated as the player walks into each respawn trigger.

eg. RespawnTracker.cs

Transform currentRespawnPos;

public void SetNewRespawn(Transform newRespawn) { currentRespawnPos = newRespawn; }

public Transform GetRespawnPosition() { return currentRespawnPos; }

Then have this script on each of the respawn triggers

RespawnTrigger.cs

// Hold reference to the RespawnTracker // Either drag and drop the reference in editor or write some code to set it RespawnTracker respawnTracker;

void OnTriggerEnter(Collider other) { // You will need to fill this out with a proper test suitable to your project // Read as psuedo code if(other == player) { respawnTracker.SetNewRespawn(transform); } }

From there, the player just needs to call the respawn tracker to get the position of the last checkpoint.

Just as a quick note, using GameObject.Find() during the game's runtime can be very slow, especially as you get more and more objects in your scene. It is better to find anything you can at the start of loading a level, or store references by dragging them onto scripts during editing where possible.

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 xToxicInferno · Feb 28, 2010 at 12:12 AM 0
Share

Yeah...this really doesn't help me as i do not understand C#. Thanks for the effort though.

avatar image
0

Answer by Ashkan_gc · Feb 28, 2010 at 03:07 PM

create a script for your player and write a code like this

function OnTriggerEnter (other : Collider)
{
   if (other.name == "spawnpoint")
   {
      this.spawnPosition = other.transform.position;
   }
}

just set the name of all spawn point gameObjects to "spawnpoint" also in the script that you create declare a variable as spawnPosition. when you die just set

transform.position = spawnPosition;
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

No one has followed this question yet.

Related Questions

Controls stop when player respawns 1 Answer

Why are floats not accessing my inputted values? 1 Answer

Position of a GameObject 2 Answers

How to follow multiple clones positions of an instantiate prefab having a velocity ? 1 Answer

scale based on position(help) 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