Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 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
1
Question by vssAndrei · May 05, 2018 at 12:10 PM · dynamicwall

Create a Dynamic Wall

Hi! I am new to unity, but not new to programming. I have a question about creating a dynamic scene;

I am following this tutorial (http://catlikecoding.com/unity/tutorials/maze/) and what i am trying to achieve is to send a JSON to my game from which i will create a house (floor, walls).

At this point i have the start point (x,y) of the wall and the end point(x,y).

     private void CreateWall (Corner start, Corner end) {
     MazeWall wall = Instantiate(wallPrefab) as MazeWall;
     Renderer wallRender = wall.GetComponentsInChildren<Renderer>()[0];
     wallRender.material.color = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f));
     var distance = Mathf.Sqrt(Mathf.Pow((end.x - start.x), 2) + Mathf.Pow((end.y - start.y), 2));
     wall.name = "Wall" + start.x + "," + start.y + "," + end.x + "," + end.y;
     wall.transform.localScale = new Vector3(distance, 1f, 1f);
     wall.transform.position = new Vector3((start.x - end.x) / 2, 0f, (start.y - end.y) / 2); }

I do not want to create a fixed size wall and then add more "unit walls" because i want to apply the same texture on one big pice. This is the expected result. I have tried to get the middle of the wall ass a point and then play with the "wall.transform.localRotation" but i think i do not use that correctly.

Thanks!

alt text

expected.png (19.0 kB)
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by vssAndrei · May 05, 2018 at 02:08 PM

Found the answer!

  private void CreateWall (Corner startCorner, Corner endCorner) {
     GameObject startObj = new GameObject();
     GameObject endObj = new GameObject();
     Vector3 start = new Vector3(startCorner.x, 1.5f, startCorner.y);
     Vector3 end = new Vector3(endCorner.x, 1.5f, endCorner.y);

     startObj.transform.localPosition = start;
     endObj.transform.localPosition = end;

     startObj.transform.LookAt(endObj.transform.position);
     endObj.transform.LookAt(startObj.transform.position);


     GameObject wall = GameObject.CreatePrimitive(PrimitiveType.Cube);


     // Set collor
     Renderer wallRender = wall.GetComponentsInChildren<Renderer>()[0];
     wallRender.material.color = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f));

     // get distance
     float distance = Vector3.Distance(start, end);

     // Set possition
     wall.name = "Wall" + start.x + "," + start.y + "," + end.x + "," + end.y;
     wall.transform.localScale = new Vector3(0.1f, 3f, distance);
     wall.transform.position = startObj.transform.position + distance / 2 * startObj.transform.forward;
     wall.transform.rotation = startObj.transform.rotation;
 }
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
0

Answer by unity_524307438 · Oct 29, 2021 at 05:59 AM

Nice, thanks for your answer!

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

81 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

Related Questions

Problem with dynamic wall 1 Answer

Problem with dynamic wall 0 Answers

Programming dynamic barriers 1 Answer

2D Top-Down: Dynamically stretch wall to enclose rectangular area? 1 Answer

Dynamic wall movement 0 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