So i have a row of cubes. I want to collide into them and when i do they get destroyed.
void OnTriggerEnter(Collider coll)
{
if(coll.gameObject.tag == "Buns")
{
incube = true;
}
}
void Update()
{
if (Input.GetKeyDown(Keycode.lol)&& incube == true)
{
//but how to distroy object? Destroy(gameObject); yea i know but how to tell what im colliding with at the moment. I dont wanna break every cube at once. Also they randomly spawn so dont say “Give each a number” or something lol
}
}
How to delete the object im colliding with when i push buttons
And whoever downvoted my question is a real sack of sweaty eyeballs
– Gaming-Dudesteri have a sprite with which i have attached your script and another a prefab assigned to "Object to spawn" variable which i want to spawn and the sprite is at layer "SpawnedObject" but still the error is coming on mouse up (doesnt matter wherever my mouse up is on the scene) ![alt text][1] [1]: /storage/temp/106572-capture.png
– tsondhi2006