Hi guys, I know this is a topic that has probably been done to death but I have not been able to find a solution as yet in all the answers.unity world and google combined. Ok so here’s the run down, I am doing a Diploma in interactive Gaming and one of my last units/modules is to make a game for mobiles, I have chosen to do an infinite runner based on a popular kids bedtime story (I have 4 kids) I have been following along with unity’s infinite 2D runner as well as many others from coffeebreak and ninjacupcake83 (I have been using his the most as it closely resembles what I wish to achieve). I have Instantiated a prefab clone of my “floor” to begin with so the player can stand upon something, I have also added a collider trigger towards the end of the “floor” which is meant to instanitate the next bit of “floor” and then delete the prefab behind me. the problem is a warning that says this
“Destroying assets is not permitted to avoid data loss.
If you really want to remove an asset use DestroyImmediate (theObject, true);
UnityEngine.Object:Destroy(Object)
GroundSpawn:OnTriggerExit(Collider) (at Assets/Scripts/GroundSpawn.cs:29)”
My code is as follows
using UnityEngine;
using System.Collections;
public class GroundSpawn : MonoBehaviour
{
// Call prefab to assign
public GameObject worldClone;
// Offset for spawning ground
public float groundOffset = 0
;
// Prefabs position (x, y, z)
public Vector3 groundSpawn = new Vector3 (0, 0, 0);
// Box Collider set up with a enter trigger function
void OnTriggerEnter (Collider other)
{
// Spawn ground on the z axis where collider centers
groundSpawn = new Vector3 (0, 0, transform.position.z + groundOffset);
Instantiate (worldClone, groundSpawn, Quaternion.identity);
}
// Box Collider set up with a exit trigger function
void OnTriggerExit(Collider other)
{
// Removes prefabs on exit of Collider
Destroy (worldClone);
}
}