Duplicate Question
How can I pick up cubes?
Hi guys, I'm trying to write a script to attach to a certain weapon that will allow me to pick up and move the cube it's aiming at, I don't need to be able to move them along the x and y axis, just moving them up and down. I have been unable to find a working tutorial on youtube or anywhere else.
Another feature I would like to implement but not right away, would be to select a limited amount of blocks to raise together, but for now I just need to be able to select a cube and raise it up into the air.
Thanks guys.
Hi @sokx_
you are asking for a tailor made solution with various steps. You don't find such often, unless your request is very generic request.
Just split your idea to smaller steps/components, and search for these.
These all have been asked here more or less, and there is abundance of tutorials in YouTube.
If you say you are trying to write a script, and you'd like to implement something - then do so - then show something you have so far, and most people can probably help you, now someone could only write the code / pseudo code for you.
Hmmm, ok, I found a tutorial that does seem to work for me, my only problem is that the cube moves on all axis and follows the camera, while it might be vague do you know how to get the selected cube to only translate along the y axis?
@sokx_ - I've got no idea what tutorial you are watching, what you have done, and how your scene setup is. Try it out properly, until you can't get further - and then form a question that anyone can understand - that way you'll help yourself and others.
Can you give us some reference about what you want to implement. Your statements are clear but not illustrative enough.
You can try using a raycast system, which you can find here: https://docs.unity3d.com/ScriptReference/Physics.Raycast.html
When the raycast hits a object, that has a matching tag or gameobject name, you can assign it as a child to the weapon: https://docs.unity3d.com/ScriptReference/Transform.SetParent.html. This will make it so that the cube thats "picked up" would be following the weapons movement.
Unity Answers is not a free coding service:
FAQ :
Some reasons for getting a post rejected:
There exists duplicate questions with answers if you were to do a search, either on Answers or on the Forum or on Unity's tutorials
Your question isn't specific enough: asking for a script, asking multiple questions in one post or asking a question that could be either subjective or require extensive discussion