Search Unity

how to add a respawn point that's activated by binded key?

Discussion in 'Scripting' started by shadowbenn, Aug 23, 2012.

  1. shadowbenn

    shadowbenn

    Joined:
    Aug 23, 2012
    Posts:
    1
    I've read a few posts but all the spawns were activated by death or completion of a level. Can anyone help me for adding a spawn that I can bind a key e.g. F1 to reset the player to the staring point?

    Thankyou in advance!
     
  2. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    Take the spawn code from an example and then look in the reference guide for Input.GetKeyDown.
    Spawning is Instantiating, which you can also find in the ref guide
     
  3. AngryPanda2000

    AngryPanda2000

    Joined:
    Dec 19, 2017
    Posts:
    1
    Could you link what you're talking about so we get a better understanding of what you are talking about.
     
  4. johne5

    johne5

    Joined:
    Dec 4, 2011
    Posts:
    1,133
    Code (CSharp):
    1. public GameObject player; //player prefab goes here
    2.  
    3. void Update()
    4. {
    5.     if (Input.GetKeyDown(keycode.f1))
    6.     {
    7.     print("F1 was pressed");
    8.     SpawnObject();
    9.     }
    10. }
    11.  
    12. void SpawnObject()
    13. {
    14.     // do code to kill and respawn the player
    15.     Destroy(player);
    16.     Instantiate(player, new Vector3(0, 0, 0), Quaternion.identity);
    17. }
     
    JustBobs likes this.