Search Unity

how to insantiate prefab after itz gets destroyed?

Discussion in 'Editor & General Support' started by themustafaa01, Apr 3, 2020.

  1. themustafaa01

    themustafaa01

    Joined:
    Jan 28, 2020
    Posts:
    2
    i am working on endless game
    prefab is my player i want to respawn it after it gets died on same position
    Code (CSharp):
    1. public  void playerSpawn() {
    2.         if (gameOn == true)
    3.         {
    4.             Instantiate(playerPrefab,transform.position,Quaternion.identity);
    5.         }
    6.  
    7.     }
    and also camera is following my player prefab position ,after player gets destroyed how to access camera again to player clone
    Code (CSharp):
    1. //camera Script
    2. private void Start()
    3.     {
    4.         player = GameObject.FindGameObjectWithTag("Player").transform;
    5.  
    6.     }
    7.    
    8.     // Update is called once per frame
    9.     void Update()
    10.     {
    11.      
    12.      
    13.       transform.position = player.position + offset;
    14.     }