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
1
Question by Fumbles · May 11, 2011 at 08:06 AM · gridclonevoxeladdminecraft

Place block script

I had put the break/place block script in my engine and when i right clicked for placing a block i got a huge gaping hole in the ground, breaking blocks with the left click works fine, Can i get a little help? This is the code..

 <p>var blockLayer : LayerMask = 1;
 var range : float = Mathf.Infinity;
 var hit : RaycastHit;</p>
 
 <p>function Update () {
     if (Input.GetMouseButtonDown(0))
         Build();
     if (Input.GetMouseButtonDown(1))
         Erase();
 }</p>
 
 <p>function Build() {
     if (HitBlock()) {
         var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
         cube.transform.position = hit.transform.position + hit.normal;
     }
 }</p>
 
 <p>function Erase() {
     if (HitBlock())
         Destroy(hit.transform.gameObject);
 }</p>
 
 <p>function HitBlock() : boolean {
     return Physics.Raycast(transform.position, transform.forward, hit, range, blockLayer);
 }</p>
          

    
Comment
Add comment · Show 1
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 Fumbles · May 11, 2011 at 08:07 AM 0
Share

$$anonymous$$y bad, I've never put a code in a post before (:

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Dreamer · May 11, 2011 at 08:42 AM

You just select all the codes, and press the "101" button on top. I help you organize the codes first, then I take a look at it.

var blockLayer : LayerMask = 1; var range : float = Mathf.Infinity; var hit : RaycastHit;

function Update () { if (Input.GetMouseButtonDown(0)) Build(); if (Input.GetMouseButtonDown(1)) Erase(); }

function Build() { if (HitBlock()) { var cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.transform.position = hit.transform.position + hit.normal; } }

function Erase() { if (HitBlock()) Destroy(hit.transform.gameObject); }

function HitBlock() : boolean { return Physics.Raycast(transform.position, transform.forward, hit, range, blockLayer); }

Comment
Add comment · Show 7 · 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 Dreamer · May 11, 2011 at 08:45 AM 0
Share

O$$anonymous$$, in this script. Left Click is to create a Cube object and Right click is to destroy the object you click on !

avatar image Fumbles · May 11, 2011 at 08:45 AM 0
Share

Oh, Haha I feel so silly now.. Okay tell me when your ready.

avatar image Fumbles · May 11, 2011 at 08:48 AM 0
Share

Well the left click was breaking blocks and the right click was breaking blocks but with a bigger size, Lol.. It may be the other scripts colliding with it or something.. I've been looking for a Break/Build script for awhile now.

avatar image ApplezGaming · Nov 01, 2012 at 11:23 PM 0
Share

i want to do the same sort of thing put to place and destroy where the mouse is not where the camera is looking could you please help change it to do that please?

avatar image henrylmoore · May 25, 2014 at 01:37 AM 0
Share

what type of format is the script

avatar image AlucardJay henrylmoore · May 25, 2014 at 03:09 AM 0
Share

Please don't post comments as answers. Post comments by clicking the [add new comment] button, a window then open for you to type in. Here at Unity Answers, Answer means Solution, not Response.

  • watch this video : http://video.unity3d.com/video/7720450/tutorials-using-unity-answers

  • read this page : http://answers.unity3d.com/page/faq.html

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Minecraft style grid and block placement? 2 Answers

problem with gap at specific radius 0 Answers

Texture mapping procedural mesh with texture atlas? (Minecraft style terrain gen) 1 Answer

Grid based water system 0 Answers

Minecraft-like ore generation 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