- Home /
Question by
Thorin1904 · Jun 02, 2017 at 09:09 AM ·
scripting problem2d gamescript.
Instantiation Disables Objects Scripts and Colliders
Hi I've made a gameManager when my object dies it activates the Sifirla method but when it instantiates new player1 and player2 , new Clones' scripts and colliders are turning false.
public static _gm ornek;
static int ASkor;
static int BSkor;
public Text AText;
public Text BText;
public GameObject player1;
public GameObject player2;
public Stack<GameObject> firlatmaKutulari = new Stack<GameObject>();
// Use this for initialization
void Awake()
{
if(ornek == null)
{
//ornek = this;
ornek = this;
}
else if(ornek != this)
{
Destroy(gameObject);
}
}
void Start () {
}
// Update is called once per frame
void Update () {
}
public void PuanArttir(string oyuncuIsmi) {
if(oyuncuIsmi == "Player1")
{
BSkor++;
TextleriAyarla();
}
else if(oyuncuIsmi == "Player2")
{
ASkor++;
TextleriAyarla();
}
}
void TextleriAyarla()
{
AText.text = ASkor.ToString();
BText.text = BSkor.ToString();
}
public void Sifirla()
{
Destroy(player1);
Destroy(player2);
GameObject player1Gecici = (GameObject)Instantiate(player1, new Vector3(-6.5f, 0, 0), Quaternion.identity);
GameObject player2Gecici = (GameObject)Instantiate(player2, new Vector3(6.5f, 0, 0), Quaternion.identity);
KutulariYokEt();
StartCoroutine("bekleme");
}
public void KutulariYokEt()
{
foreach(GameObject g in firlatmaKutulari)
{
Destroy(g);
}
}
IEnumerator bekleme()
{
Time.timeScale = 0;
yield return new WaitForSecondsRealtime(3f);
Time.timeScale = 1;
}
}
Comment
Answer by ShadyProductions · Jun 02, 2017 at 09:10 AM
GameObject player1Gecici = (GameObject)Instantiate(player1, new Vector3(-6.5f, 0, 0), Quaternion.identity);
GameObject player2Gecici = (GameObject)Instantiate(player2, new Vector3(6.5f, 0, 0), Quaternion.identity);
Destroy(player1);
Destroy(player2);
Try create copies first before you destroy the initial ones.
Your answer
![](https://koobas.hobune.stream/wayback/20220612123042im_/https://answers.unity.com/themes/thub/images/avi.jpg)