- Home /
Deleting a Prefab when it is dragged to a GUI Texture
So far I know how to do this with a GameObject, but I'm finding it hard to do with GUI Textures, In fact, I'm finding everything about Unity's OnGUI terrible, but whatever. So here's my code with a GameObject:
using UnityEngine;
using System.Collections;
public class Deleter : MonoBehaviour {
public GameObject deleter;
private GameObject object;
void Update() {
object = GameObject.FindWithTag("picked");
if (object != null) {
if (deleter.collider.bounds.Intersects (object.collider.bounds)) {
Destroy (object);
}
}
}
}
So How do I do the same but instead of being a GameObject, "deleter" is a GUITexture.
Also I should probably ask which good 'GUI Creators' do you know in the Asset Store?
A GUITexture is very different from GUI. The GUI uses OnGUI() and draws a texture using GUI.DrawTexture. GUITextures do not. What you are trying to do is confusing since all the objects in the example code live in world space. GUITextures are 2D and live in Viewport space. So I'm not sure what kind of intersection you want to calculate.
Basically I want Instantiated GameObjects(prefabs) and a GUITexture, to interact. So the GUITexture deletes any object that comes in contact with it (dragged with the mouse)