Is there a way to make clickable/interactable particles in Unity? - c#

I want to create a bubble-pop mechanic where bubbles will fall from the top of the screen, and the player will be able to 'pop' them by clicking/tapping on them.
Basically this: https://www.youtube.com/watch?v=OH4dcpSk7n0
I started by creating a particle system. But is there a way to attach a script to the particle? Or should I go about it in a completely different way?

you should not use particles to achieve this, instead you should make a GameObject with rigidBody and collider attached to it, and spawn those GameObjects in the position you want.

Related

Specify all GameObjects?

I was wondering if there was a way to specify all game objects. I am trying to calculate the distance between the player and the grounds/every game object but the player and what it's made up of. anyway, if anyone knows how to get the distance of the nearest gameobject to the player please let me know.
You can get all GameObjects in your Scene using GameObject.FindGameObjectsOfType<GameObject>() because this will get every GameObject that is a GameObject, meaning everyone.
If you also want to get inactive GameObjects, you can use GameObject.FindGameObjectsOfType<GameObject>(true)
However, I don't think you really want every GameObject. You probably either want everyone that has a collider or everyone that has a Renderer.
If you want to get all GameObjects with a Collider, you can use GameObject.FindGameObjectsOfType<Collider>() for 3D Colliders or GameObject.FindGameObjectsOfType<Collider2D>() for 2D Colliders
If you want to get all GameObjects wich are being rendered, you can use GameObject.FindGameObjectsOfType<Renderer>().
Of course, you can put true between the parentheses of all of these to get inactive ones too.
However
It's generally not a good idea to get so many objects because it's very bad for performance.

Looking for a way to make a cube in which game objects bounce around

My question is quite simple. How do I make a cube which has other game objects inside of it, and can detect when those objects collide with sides of the cube. I can just use a collider for each of the sides but I want to be able to shrink and grow the cube while the program is running. If I used a collider for each of the sides I would have to move each of them individually. Is there a way to use just one collider on the cube?
Place six flat cubes around with a thin collier box and then make parent them to an empty game object.

How best to modify colliders to affect pickup area for character?

I am making a simple inventory/equipment system with a basic square character. One of the items you can use is a potion that will increase the pickup item area. I have a way to do this already, but I am wondering if there is a better way to do this?
WHAT I CURRENTLY HAVE
I have a collider on my character object, which deals with collisions with the walls and general world (all this handled in the Player script).
I then have an empty gameObject child of this object, which has a collider component the same size as the other collider (at start).
The child gameObject has a script (PickupAreaModifier script) with a OnTriggerEnter2D function that calls a method in the main character script to add the item.
If the item is the potion, then the Player script calls a method in the PickupAreaModifier script to change the size of that collider.
WHAT I WANT
This current logic works, but I would like to know if there is a more efficient way to handle this, especially considering the OnTriggerEnter2D function needing to be called on the child gameObject script. Is there any way I can handle this in only the Player script?
Thank you in advance, I hope that makes sense!

How to detect collisions for a rotating child object in Unity3D C#?

I am making a First Person Shooter and I have a rigged player with a mouse look script, and I used to rotate the spine with spine.transform.rotation, but this method does not look for collisions, this means if I rotate and I am standing near to a GameObject, I glitch/bug through the object. So I tried to do it with a Rigidbody but this doesn't seem to work, I tried: rbSpine.AddTorque(new Vector3(mouseLook.y,0,0), ForceMode.Force);. This doesn't do anything. And I have another problem with the Rigidbody, I've only a rigidbody attached to the spine, my player has multiple simple collision and these overlap eachother a little, and my rigidbody is pushed away into the air slowly. Does anyone know a solution for this?
I put a rigidbody component on the player, this will take care of the collision detection for itself and all its child objects.

Jiggling a gameobject in Unity

How do I make a gameobject like a sphere to jiggle in space, meaning rapidly moving around in random directions while holding it's original position.
I know I can come up with some really long codes to kind of simulate this but I was wondering if there is a trick to it.
Thanks
I think what you want are joints. You can attach a spring joint component to a gameObject with a rigidbody. On the spring joint, set the connected body to a seperate gameObject with a kinematic rigidbody, then play with the spring joint settings until you get a nice jiggle effect. Probably increase the Spring value a bunch.

Categories