Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by ArtyomIsFlash · Jun 17, 2016 at 02:26 PM · c#minecraftblock

How to fix the blocks placement?

I have a script that places blocks. But when I look down, it places one on the top of me. How to fix it?

 using UnityEngine;
 using System.Collections;
 
 public class Build : MonoBehaviour
 {
     public GameObject prefabToCreate;
     public Transform sillouetteTransform;
     Vector3[] positions = new Vector3[256];
     int currentArrayPos = 0;
     Ray ray;
     RaycastHit raycastHitInfo;
     Vector3 placePos;
     bool canBuild = true;
     bool canShowSlt = true;
 
     void FixedUpdate()
     {
         ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(ray, out raycastHitInfo, 10))
         {
             placePos = new Vector3(Mathf.Floor(raycastHitInfo.point.x), Mathf.Floor(raycastHitInfo.point.y), Mathf.Floor(raycastHitInfo.point.z));
             for (int i = 0; i <= 255; i++)
             {
                 if (positions[i] == placePos)
                 {
                     canShowSlt = false;
                     break;
                 }
             }
             if (canShowSlt)
             {
                 sillouetteTransform.gameObject.SetActive(true);
                 sillouetteTransform.position = placePos;
             } else
             {
                 canShowSlt = true;
                 sillouetteTransform.gameObject.SetActive(false);
             }
             if (Input.GetMouseButtonDown(1))
             {
                 for (int i = 0; i <= 255; i++)
                 {
                     if (positions[i] == placePos)
                     {
                         canBuild = false;
                         break;
                     }
                 }
                 if (currentArrayPos > 255)
                 {
                     canBuild = false;
                 }
                 if (canBuild)
                 {
                     Instantiate(prefabToCreate, placePos, new Quaternion());
                     positions[currentArrayPos] = placePos;
                     currentArrayPos += 1;
                 }
                 else
                 {
                     canBuild = true;
                 }
             }
         }
     }
 }

Also, there are other placement bugs.

Comment
Add comment · Show 4
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 ArtyomIsFlash · Jun 17, 2016 at 02:49 PM 0
Share

Please, somebody help! I don't want to ask it on StackOverflow because if my question will be not well-recieved, I'll be banned from asking the questions.

avatar image ArtyomIsFlash · Jun 17, 2016 at 02:58 PM 0
Share

Will someone respond? Often, blocks can't be placed!

avatar image ArtyomIsFlash ArtyomIsFlash · Jun 17, 2016 at 02:58 PM 0
Share

Or being placed multiple times

avatar image Cherno ArtyomIsFlash · Jun 17, 2016 at 03:07 PM 1
Share

For god's sake, please wait at least a couple of hours before bumping your thread like that. You posted the question 38 $$anonymous$$utes ago, not a very long time for people to notice your thread, read it, try to understand it, find the error, and write a solution.

The first thing you should do is inserting Debug.Log lines to get an idea which parts of your code cause problems.

Also: "there are other placement bugs" is not very descriptive. f you need help, provide as much information as possible. Added points for describing what your code does in detail and posting schematics.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ollobin · Jun 17, 2016 at 03:43 PM

Please give more detail. However what I think is happening is that at the start you say if the raycast hits the floor the block is created, or so I think. I might be wrong. But when you say that, and you look down, obviously the raycast hits the floor right under you, and the block can't be made inside of you, so it goes on top of you. I hope this helps, but please be more specific as to what you want.

The problem:

  void FixedUpdate()
  {
      ray = Camera.main.ScreenPointToRay(Input.mousePosition);
      if (Physics.Raycast(ray, out raycastHitInfo, 10))
      {
          placePos = new Vector3(Mathf.Floor(raycastHitInfo.point.x), Mathf.Floor(raycastHitInfo.point.y), Mathf.Floor(raycastHitInfo.point.z));
          for (int i = 0; i <= 255; i++)<
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

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

Related Questions

Integer arrays not comparing properly. 3 Answers

IndexOutOfRangeException: Index was outside the bounds of the array. (wrapper managed-to-managed) System.Object.ElementAddr_1(object,int,int,int) 0 Answers

How do I emulate Minecraft Redstone 0 Answers

How to hide faces of a mesh that I dont see? 1 Answer

Object reference not set to an instance of an object 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