- Home /
,Reseting the Position of an Object
I am making a simple 3d racing game, and am trying to make a killzone that teleports the player back to the starting position. However, all it does is delete my vehicle. I have looked on several forums and watched videos but it is not woking. My code:
public class KillZone : MonoBehaviour
{
public GameObject Zone;
public GameObject Car;
public Vector3 Spawn;
void Start()
{
Spawn = new Vector3(Car.transform.position.x, Car.transform.position.y, Car.transform.position.z);
}
void OnTriggerEnter(Collider other)
{
Car.transform.position = Spawn;
}
}
I am not an expert at C# but not a total beginner.
$$anonymous$$aybe you have another script deleting the car on trigger enter.
BTW, Why not Spawn = Car.transform.position;
in your Start() ??
Answer by tormentoarmagedoom · Jan 29, 2019 at 05:09 PM
Good day.
As @ConcanoPayno says,
At Start you can directly use
Spawn = Car.transform.position;
Second, all seems ok, this script is not destroying the gameobject. You should check all your scripts, to discover why is destroyed. You should make a "Find" in your scripting program for the word "Destroy" to see why is this happening.
IT seems more you made a logical error destroying it when you dont want to.
Good luck!