Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by SneakySoV · Oct 10, 2010 at 10:40 AM · raycastcubetexturecoord

Raycast textureCoord

Hello, I've been working with Unity3D for a couple of days now, and I'm stuck! I use the following code to create a platform using 1x1x1 cubes:

function Start() { for (var x : int = 0; x < 40; x++) { for (var y : int = 0; y < 40; y++) { count ++;

         block = Instantiate (BlockPrefab, Vector3(1.0 + (1.0 * x), 0.0, 1.0 + (1.0 * y)), Quaternion.identity) as Transform;

         block.name = "block_" + count;
         //Debug.Log(block.name);
     }
 }

}

This works just fine. Now what I want to achieve is being able to left click my mouse on a cube (I call them blocks in script) then create an other top right on top of the cube I clicked (my ultimate goal is being also able to click on a side of a cube and it will create a cube on that side), this is what I've got so far:

function Update () { if(Input.GetButtonDown("Fire1")) { var hit : RaycastHit;

     var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);

     if (Physics.Raycast (ray, hit))
     {
         var newPosition = Vector3(hit.point.x, hit.point.y+1, hit.point.z);

         block = Instantiate (BlockPrefab, newPosition, Quaternion.identity);
         count ++;
         block.name = "block_" + count;

         Debug.Log(hit.collider.gameObject.name);
         //Debug.Log(hit.textureCoord);
     }
 }

}

This creates the cube at any point in the map I click, except for empty spaces, I tried using Raycast textureCoord but it always creates the cube at 0,0,0. I found on answers.unity3d.com that I had to use a mesh collider for the cube and that's what I did but it still doesn't work.

What do I have to do to make it work?

Comment
Add comment · Show 2
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 Bampf · Oct 10, 2010 at 04:56 PM 0
Share

Sorry, I've read what you wrote a few times and I can see what you are trying to do, but I'm not clear on what part of it isn't working. Can you please clarify?

avatar image SneakySoV · Oct 12, 2010 at 08:59 AM 0
Share

Thanks. When I press Fire1 (L$$anonymous$$B) it does create the cube at the point I want it to, but I want to create the cube on top of a cube I click using raycast texturecoord, but when using raycast texturecoord it always creates the cube at 0,0,0 (on top of the first cube) at not on top of the cube I click.

I tried this:

var newPosition = Vector3(hit.textureCoord.x, hit.textureCoord.y+1, 0); block = Instantiate (BlockPrefab, newPosition, Quaternion.identity);

Bare in $$anonymous$$d this is just a simple test for me to learn Unity3D.

0 Replies

· Add your reply
  • Sort: 

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

No one has followed this question yet.

Related Questions

Why in Unity3D RaycastHit. textureCoord always return 0,0 after building the project? 1 Answer

Sphercast hitinfo TextureCoord rounded? 1 Answer

Detect if object is a cube(find the primitive type) with physics.raycast 2 Answers

Painting on a texture without crossing mesh triangle. 1 Answer

How i can create a cube with specific coordenates? 3 Answers


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