Author Topic: How do you respawn a player?  (Read 2022 times)

tomgsx

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
How do you respawn a player?
« on: August 13, 2014, 01:40:35 PM »
I currently have a basic setup similar to your YouTube video where the initial scene uses TNAutoJoin and the game scene creates the player with TNAutoCreate. When any object is hit with a weapon, the following line is executed:

TNManager.Destroy(x.transform.gameObject);

At this point I want to respawn the object in the prefab's default position if the object destroyed was a player. I initially thought simply using Application.LoadLevel(1) would work since that scene contains TNAutoCreate, but it didn't seem to work out as intended. I would appreciate your help, thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How do you respawn a player?
« Reply #1 on: August 14, 2014, 08:20:55 AM »
TNManager.Create it? I'm not sure if I understand the question. That's what TNAutoCreate does inside.

In Windward I use custom creation functions as I need to ass additional info to the create call -- such as the unit's faction.

tomgsx

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: How do you respawn a player?
« Reply #2 on: August 14, 2014, 12:01:36 PM »
Disregard, I figured it out. Was my error on the respawn script. First I had it attached to the object being destroyed, which clearly wasn't working. Then I had put it on an object I instantiated over the network - resulting in more ships respawning for no reason. Finally I figured it out and just placed it on a gameobject in the scene with a timer that resets and TNManager.Create's the new player if "myPlayer" is null.

For some reason I approached the respawn initially with the idea that simply restarting the scene would be simple since everything necessary to the player and dependent assignments happens when the Game scene is loaded. TNManager.Create worked just fine.

Rexima

  • Jr. Member
  • **
  • Thank You
  • -Given: 7
  • -Receive: 2
  • Posts: 78
    • View Profile
Re: How do you respawn a player?
« Reply #3 on: August 20, 2014, 08:13:25 AM »
You can disable the Player GameObject and reset all variables like health etc. and set the position to your respawn point and enable the player again.
That's how i make it.