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 DisDoesGames · Jul 09, 2013 at 05:20 PM · buildingminecraftblocks

Can someone fix this building and breaking code?

I have a building and breaking block code for this game like Minecraft that I'm making. I click and I can get stuck in blocks. Also Sometimes when I click my Player gets deleted and I can't do anything unless I exit the game. I don't know if it's the code or something Please Help.

 var GrassBlock : Transform;
 var StoneBlock : Transform;
 var BlockSelected : float = 1;
 var Range : float = 20;
 
 function Update () 
 {
 if (Input.GetKeyDown(KeyCode.Q))
     {
         BlockSelected -= 1;    
     }
 
 if (Input.GetKeyDown(KeyCode.E))
     {
         BlockSelected += 1;    
     }
     
 if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))
     {
         var Hit : RaycastHit;
         var LookingDirection = transform.TransformDirection(Vector3.forward);
         
         if (Physics.Raycast(transform.position,LookingDirection, Hit, 20))
 {
         
         if (Input.GetMouseButtonDown(1))
         {
         
         if (BlockSelected == 1)
         {
         var GrassBlock : Transform = Instantiate(GrassBlock, Hit.collider.transform.position + Hit.normal.normalized, Quaternion.identity);
         GrassBlock.tag = "GrassBlock";
         }
         
         if (BlockSelected == 2)
         {
         var StoneBlock : Transform = Instantiate(StoneBlock, Hit.collider.transform.position + Hit.normal.normalized, Quaternion.identity);
         GrassBlock.tag = "StoneBlock";
         }
         }
     
     
     else
     {
     Destroy(Hit.transform.gameObject);
     }
 }    
 }
 }
Comment
Add comment · Show 3
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 tw1st3d · Jul 09, 2013 at 05:36 PM 0
Share

Well I see that you're defining floats as a solid number, 1 and 10, ins$$anonymous$$d of 1.0f and 10.0f, however I don't know if that will do anything differently. Also, add in some debug logs for every if statement so you can see what the last thing that happened was before you get stuck. I'm thinking that it's getting a little stuck when it's trying to listen for Q, E, Left Click, and Right Click, because your statements aren't nested properly.

avatar image Lo0NuhtiK · Jul 09, 2013 at 05:39 PM 0
Share

unityScript doesn't care about the 'f'

avatar image AlucardJay · Jul 09, 2013 at 06:40 PM 0
Share

A hit normal is already normalized

Check if the block will be instantiated too close to the player, if so then don't instantiate it.

Before you destroy the gameObject, check to make sure it is not the player first.

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

18 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Help! Saving blocks in a grid-based building system 0 Answers

MaK like building script help... 0 Answers

Trouble with Minecraft like building 0 Answers

Cannot convert 'UnityEngine.GameObject' to 'UnityEngine.Transform' 1 Answer

Road Texture Is Stretching 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