Question by
SawellD · Apr 07 at 06:00 AM ·
spawningpositioningrespawnreset
Save the Position of Prefab and Respawn it
using System.Collections;
using System.Collections.Generic;
using SystemUnityEngine;
public class Reset : MonoBehavior
{
public GameObject Cubes;
public Vector3 originalPos;
void Start()
{
originalPos = Cubes.transform.position;
}
public void reset() // Here i want to delete the old Cubes and Spawn them
// at the originalPos again so that they are an the same Pos as in the start
{
Destroy(Cubes);
Thread.Sleep(300);
//I've tried
//GameObject spawnedCubes = Instantiate(Cubes, originalPos);
// spawnedCubes.GetComponent<Rigidbody>();
}
}
Comment
Explanation of what i try to do: the script should save the position in the void start() and in the public void reset() it should delete the old cubes and new ones should be respawed at the position stored in the void start(). I would aprecciate every help to this topic.
Answer by SawellD · Apr 07 at 06:10 PM
I have changed the code now to this
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Reset : MonoBehaviour
{
public GameObject CubesPre;
public Vector3 originalPos;
public Quaternion originalRot;
void Start()
{
originalPos = CubesPre.transform.position;
originalRot = CubesPre.transform.rotation;
}
public void reset()
{
Destroy(CubesPre);
System.Threading.Thread.Sleep(500);
Instantiate(CubesPre, originalPos, originalRot);
}
but if i Instaniate my CubesPre the Cubes which are in my CubesPre dont change their position as they are assigned in the CubesPre so if my Cubes are out of order i use public void reset() and the should move back to this
But they just stay out of order any ideas?
cubeschangedpos.png
(27.4 kB)
cubesoriginalpos.png
(13.7 kB)