Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
-3
Question by coolthemanp6p · Dec 27, 2011 at 11:59 AM · gameobjectdestroycreateminecraftfaces

Placing a cube on the face of another

Something like minecraft

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lo0NuhtiK · Dec 27, 2011 at 01:54 PM 1
Share

Get one cube, get another, stack as needed.

avatar image Julien-Lynge · Dec 27, 2011 at 05:27 PM 0
Share

We're really going to need a more specific question to give you a proper answer. What exactly are you trying to do, what have you already tried (code samples or descriptions), what specifically isn't working / doesn't do what you expect, etc.

If you don't yet know enough about Unity to get started attempting to recreate $$anonymous$$inecraft, then I suggest you check out the Unity basics and tutorials:

http://unity3d.com/support/documentation/

FYI, my guess for why your question got downvoted is that it's vague and kind of comes across as you wanting someone else to do all the work for you. Since you're the game developer, it's up to you to figure out how your game should work, and the community is here to answer technical questions and respond to bugs, not to write tutorials on how to recreate $$anonymous$$inecraft in Unity.

avatar image coolthemanp6p · Dec 27, 2011 at 06:51 PM 0
Share

Ive created unity games before and know how unity works I even make tutorials on youtube. I just need to know if how to like place a block on the face I click on. I have no code right now though.

avatar image NoseKills coolthemanp6p · Apr 20, 2017 at 03:23 PM 0
Share

In that case your question should at least mention which part you are having problems with: creating the cubes, positioning them, clicking on a cube, detecting which face was clicked or something else...

Breaking it in parts like that, maybe you already noticed you can do some of those or find answers to the ones you can't with search/google.

avatar image Bunny83 · Dec 28, 2011 at 01:17 AM 0
Share

"created unity game*s* before"? If you have a little bit of Unity experience and a bit of general game development experience that's a quite simple question. Did you even search for something similar before? Just a search for "$$anonymous$$ecraft" on this site should be more than enough

avatar image ina · Dec 28, 2011 at 01:25 AM 0
Share

guessing he means those silly drag and drop tutorials, or modifying the FPS island example that came out of the box

4 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by Bilelmnasser · Apr 20, 2017 at 09:31 AM

place this script inside your scene with a cube and click play :

  void Update () {
 
 
 
         if ( Input.GetMouseButtonDown( 0 ) )
         {
             Ray ray = Camera.main.ScreenPointToRay( Input.mousePosition );
             RaycastHit hit;
             if ( Physics.Raycast( ray , out hit , 2000 ) )
             {
                 // it's better to find the center of the face like this:
                 Vector3 position = hit.transform.position + hit.normal ;
 
                 // calculate the rotation to create the object aligned with the face normal:
                 Quaternion rotation =  Quaternion.FromToRotation( Vector3.up , hit.normal );
                 // create the object at the face center, and perpendicular to it:
                 GameObject Placement = GameObject.CreatePrimitive( PrimitiveType.Cube );
                 Placement.transform.position = position;
                 Placement.transform.rotation = rotation;
 
 
 
                 //Instantiate<( PrimitiveType.Cube as GameObject , position , rotation ) as GameObject;
             }
             else
             {
                 Debug.Log( "nothing" );
             }
         }
 
 
     } 
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DmitryKanunnikoff · Dec 13, 2017 at 01:01 PM 1
Share

Thank you very much!

avatar image Unshackled · Dec 13, 2017 at 02:04 PM 1
Share

Thanks! This needs more attention!

avatar image
3

Answer by Statement · Dec 28, 2011 at 04:11 AM

Not the most descriptive question I've seen... However, if you want some working example, here's a package I wrote some time ago, and I even have a blog post regarding some thoughts about it.

It contains a scene and scripts to generate voxels.

alt text

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
2

Answer by Julien-Lynge · Dec 27, 2011 at 07:07 PM

To do what you've asked, "place a block on the face I click on", here's what you will need:

http://unity3d.com/support/documentation/ScriptReference/Input-mousePosition.html

http://unity3d.com/support/documentation/ScriptReference/Camera.ScreenPointToRay.html

Collider.Raycast

(as well as http://unity3d.com/support/documentation/ScriptReference/RaycastHit.html for point and normal)

Object.Instantiate

Good luck!

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image coolthemanp6p · Dec 27, 2011 at 10:11 PM 0
Share

Thanks very helpful!

avatar image Bunny83 · Dec 28, 2011 at 01:05 AM 0
Share

It's much more useful to click the upvote-button than posting a comment that says "Thank you" ;)

Don't get it wrong, the comment is really nice, but a Q&A site should offer the best solution (Answer) first. We as the community are responsible to judge what's useful and what's not.

Be careful with downvotes and if you do so always post a comment which explains what's wrong. Downvotes should only be used when it clearly wrong.

avatar image ina · Dec 28, 2011 at 01:07 AM 0
Share

Creating some sort of discrete coordinate system/grid system may also be relevant, i.e., to figure out the coordinate in which to spawn the other cube.

avatar image
0

Answer by Jure · Dec 28, 2011 at 03:33 AM

I made a prefab out of cubes that are allready in unity and this is a code to spawn them in 2D grid. There is also few lines which make middle tile pruple and align camera to the center:

 var tilePrefab : GameObject;
 var y : int = 10; 
 var x : int = 10; 
 var initialColor : Color;
 
 function Start (){
   for (var i : int = 0;i &lt; y; i++) {
     for (var j : int = 0; j &lt; x; j++)
     {
       var tile : GameObject = Instantiate (tilePrefab, Vector3(j, i, 0), Quaternion.identity);
       if (i == y/2 &amp;&amp; j == x/2)
       {
         print("test");
         var pos: Vector3 = tile.transform.position; // get the tile position...
         pos.z = Camera.main.transform.position.z; // but keep the camera z 
         Camera.main.transform.position = pos; // move camera to the position
         tile.renderer.material.color = Color.cyan;
 8//,b
       }
     }
   }
 }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Create Object when other Object hits ground. 1 Answer

"Transform" still trying to access after Destroy 0 Answers

How to insert an object after Destroy(gameObject) 2 Answers

Checking Instantiate/Destroy has been called | Checking number of scene GameObjects 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges