Unity - How to respawn a Gameobject after destroy

后端 未结 2 382
我寻月下人不归
我寻月下人不归 2021-01-14 19:39

I\'m Using unity for developing my game. I\'ve created a simple game just like football after scoring a goal the ball should be destroyed and then reappear at its original p

2条回答
  •  甜味超标
    2021-01-14 20:05

    You can try respawning the object by using this script -
    
    
    
    
    using UnityEngine;
    using System.Collections;
    
    public class copy : MonoBehaviour
    {
    
    
    
    
         [SerializeField]
        private GameObject prefab = null; // assign Cube prefab to this in Editor
        void Start()
        {
            // no need for a local prefab variable, nor a call to Resources.Load();
            for (int i = 0; i < 4; ++i)
            {
                Instantiate(prefab, new Vector3(0, i * 10, 0), Quaternion.identity); // you can directly assign position in Instantiate
            }
        }
    
    }
    

提交回复
热议问题