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 /
avatar image
0
Question by Chocolade · Feb 06, 2018 at 07:51 PM · c#scripting problemscript.

Why when creating new GameObjects I can't move them in the editor when the game is running ?

Move them I mean drag them in the scene view window when the game is running. The new objects myLine won't move.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine.Tilemaps;
 using UnityEngine.WSA;
 
 public class ShowMeshBounds : MonoBehaviour
 {
     public Color color = Color.green;
     
     private Vector3 v3FrontTopLeft;
     private Vector3 v3FrontTopRight;
     private Vector3 v3FrontBottomLeft;
     private Vector3 v3FrontBottomRight;
     private Vector3 v3BackTopLeft;
     private Vector3 v3BackTopRight;
     private Vector3 v3BackBottomLeft;
     private Vector3 v3BackBottomRight;
 
     private void Start()
     {
         CalcPositons();
         DrawBox();
     }
 
     void CalcPositons()
     {
         Bounds bounds = GetComponent<MeshFilter>().sharedMesh.bounds;
         
         Vector3 v3Center = bounds.center;
         Vector3 v3Extents = bounds.extents;
 
         v3FrontTopLeft = new Vector3(v3Center.x - v3Extents.x, v3Center.y + v3Extents.y, v3Center.z - v3Extents.z);  // Front top left corner
         v3FrontTopRight = new Vector3(v3Center.x + v3Extents.x, v3Center.y + v3Extents.y, v3Center.z - v3Extents.z);  // Front top right corner
         v3FrontBottomLeft = new Vector3(v3Center.x - v3Extents.x, v3Center.y - v3Extents.y, v3Center.z - v3Extents.z);  // Front bottom left corner
         v3FrontBottomRight = new Vector3(v3Center.x + v3Extents.x, v3Center.y - v3Extents.y, v3Center.z - v3Extents.z);  // Front bottom right corner
         v3BackTopLeft = new Vector3(v3Center.x - v3Extents.x, v3Center.y + v3Extents.y, v3Center.z + v3Extents.z);  // Back top left corner
         v3BackTopRight = new Vector3(v3Center.x + v3Extents.x, v3Center.y + v3Extents.y, v3Center.z + v3Extents.z);  // Back top right corner
         v3BackBottomLeft = new Vector3(v3Center.x - v3Extents.x, v3Center.y - v3Extents.y, v3Center.z + v3Extents.z);  // Back bottom left corner
         v3BackBottomRight = new Vector3(v3Center.x + v3Extents.x, v3Center.y - v3Extents.y, v3Center.z + v3Extents.z);  // Back bottom right corner
 
         v3FrontTopLeft = transform.TransformPoint(v3FrontTopLeft);
         v3FrontTopRight = transform.TransformPoint(v3FrontTopRight);
         v3FrontBottomLeft = transform.TransformPoint(v3FrontBottomLeft);
         v3FrontBottomRight = transform.TransformPoint(v3FrontBottomRight);
         v3BackTopLeft = transform.TransformPoint(v3BackTopLeft);
         v3BackTopRight = transform.TransformPoint(v3BackTopRight);
         v3BackBottomLeft = transform.TransformPoint(v3BackBottomLeft);
         v3BackBottomRight = transform.TransformPoint(v3BackBottomRight);
     }
 
     void DrawBox()
     {
         SpawnLineGenerator(v3FrontTopLeft, v3FrontTopRight, color);
         SpawnLineGenerator(v3FrontTopRight, v3FrontBottomRight, color);
         SpawnLineGenerator(v3FrontBottomRight, v3FrontBottomLeft, color);
         SpawnLineGenerator(v3FrontBottomLeft, v3FrontTopLeft, color);
 
         SpawnLineGenerator(v3BackTopLeft, v3BackTopRight, color);
         SpawnLineGenerator(v3BackTopRight, v3BackBottomRight, color);
         SpawnLineGenerator(v3BackBottomRight, v3BackBottomLeft, color);
         SpawnLineGenerator(v3BackBottomLeft, v3BackTopLeft, color);
 
         SpawnLineGenerator(v3FrontTopLeft, v3BackTopLeft, color);
         SpawnLineGenerator(v3FrontTopRight, v3BackTopRight, color);
         SpawnLineGenerator(v3FrontBottomRight, v3BackBottomRight, color);
         SpawnLineGenerator(v3FrontBottomLeft, v3BackBottomLeft, color);
     }
 
     void SpawnLineGenerator(Vector3 start, Vector3 end, Color color)
     {
         GameObject myLine = new GameObject();
         myLine.tag = "FrameLine";
         myLine.name = "FrameLine";
         myLine.transform.position = start;
         myLine.AddComponent<LineRenderer>();
         LineRenderer lr = myLine.GetComponent<LineRenderer>();
         lr.material = new Material(Shader.Find("Particles/Alpha Blended Premultiply"));
         lr.startColor = color;
         lr.endColor = color;
         lr.startWidth = 0.03f;
         lr.endWidth = 0.03f;
         lr.SetPosition(0, start);
         lr.SetPosition(1, end);
     }
 }

Screenshot showing me trying to drag one of the new gameobjects but it's not moving:

Won't move

trytomove.jpg (291.8 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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by cooldude5757 · Feb 07, 2018 at 07:35 AM

In the line renderer parameters, disable Use World Space and you can move your game objectalt text

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine.Tilemaps;
 using UnityEngine.WSA;
 
 public class ShowMeshBounds : MonoBehaviour
 {
     public Color color = Color.green;
 
     public Vector3 v3FrontTopLeft;
     public Vector3 v3FrontTopRight;
     public Vector3 v3FrontBottomLeft;
     public Vector3 v3FrontBottomRight;
     public Vector3 v3BackTopLeft;
     public Vector3 v3BackTopRight;
     public Vector3 v3BackBottomLeft;
     public Vector3 v3BackBottomRight;
 
     private void Start()
     {
         CalcPositons();
         DrawBox();
     }
 
     void CalcPositons()
     {
         Bounds bounds = GetComponent<MeshFilter>().sharedMesh.bounds;
 
         Vector3 v3Center = bounds.center;
         Vector3 v3Extents = bounds.extents;
 
         v3FrontTopLeft = new Vector3(v3Center.x - v3Extents.x, v3Center.y + v3Extents.y, v3Center.z - v3Extents.z);  // Front top left corner
         v3FrontTopRight = new Vector3(v3Center.x + v3Extents.x, v3Center.y + v3Extents.y, v3Center.z - v3Extents.z);  // Front top right corner
         v3FrontBottomLeft = new Vector3(v3Center.x - v3Extents.x, v3Center.y - v3Extents.y, v3Center.z - v3Extents.z);  // Front bottom left corner
         v3FrontBottomRight = new Vector3(v3Center.x + v3Extents.x, v3Center.y - v3Extents.y, v3Center.z - v3Extents.z);  // Front bottom right corner
         v3BackTopLeft = new Vector3(v3Center.x - v3Extents.x, v3Center.y + v3Extents.y, v3Center.z + v3Extents.z);  // Back top left corner
         v3BackTopRight = new Vector3(v3Center.x + v3Extents.x, v3Center.y + v3Extents.y, v3Center.z + v3Extents.z);  // Back top right corner
         v3BackBottomLeft = new Vector3(v3Center.x - v3Extents.x, v3Center.y - v3Extents.y, v3Center.z + v3Extents.z);  // Back bottom left corner
         v3BackBottomRight = new Vector3(v3Center.x + v3Extents.x, v3Center.y - v3Extents.y, v3Center.z + v3Extents.z);  // Back bottom right corner
 
         v3FrontTopLeft = transform.TransformPoint(v3FrontTopLeft);
         v3FrontTopRight = transform.TransformPoint(v3FrontTopRight);
         v3FrontBottomLeft = transform.TransformPoint(v3FrontBottomLeft);
         v3FrontBottomRight = transform.TransformPoint(v3FrontBottomRight);
         v3BackTopLeft = transform.TransformPoint(v3BackTopLeft);
         v3BackTopRight = transform.TransformPoint(v3BackTopRight);
         v3BackBottomLeft = transform.TransformPoint(v3BackBottomLeft);
         v3BackBottomRight = transform.TransformPoint(v3BackBottomRight);
     }
 
     void DrawBox()
     {
         SpawnLineGenerator(v3FrontTopLeft, v3FrontTopRight, color);
         SpawnLineGenerator(v3FrontTopRight, v3FrontBottomRight, color);
         SpawnLineGenerator(v3FrontBottomRight, v3FrontBottomLeft, color);
         SpawnLineGenerator(v3FrontBottomLeft, v3FrontTopLeft, color);
 
         SpawnLineGenerator(v3BackTopLeft, v3BackTopRight, color);
         SpawnLineGenerator(v3BackTopRight, v3BackBottomRight, color);
         SpawnLineGenerator(v3BackBottomRight, v3BackBottomLeft, color);
         SpawnLineGenerator(v3BackBottomLeft, v3BackTopLeft, color);
 
         SpawnLineGenerator(v3FrontTopLeft, v3BackTopLeft, color);
         SpawnLineGenerator(v3FrontTopRight, v3BackTopRight, color);
         SpawnLineGenerator(v3FrontBottomRight, v3BackBottomRight, color);
         SpawnLineGenerator(v3FrontBottomLeft, v3BackBottomLeft, color);
     }
 
     void SpawnLineGenerator(Vector3 start, Vector3 end, Color color)
     {
         GameObject myLine = new GameObject();
 
         myLine.tag = "FrameLine";
         myLine.name = "FrameLine";
 
         myLine.AddComponent<LineRenderer>();
         LineRenderer lr = myLine.GetComponent<LineRenderer>();
         lr.material = new Material(Shader.Find("Particles/Alpha Blended Premultiply"));
         lr.startColor = color;
         lr.useWorldSpace = false;
         lr.endColor = color;
         lr.startWidth = 0.03f;
         lr.endWidth = 0.03f;
         lr.SetPosition(0, start);
         lr.SetPosition(1, end);
 
     }
 }

capture.png (235.2 kB)
Comment
Add comment · Show 4 · 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 Chocolade · Feb 07, 2018 at 07:38 AM 0
Share

You right and I did it already. The problem is when disabling it the lines positions changed. I can't figure out how to re position them back to the original positions before the disabling.

After disabling the Use World Space

avatar image cooldude5757 Chocolade · Feb 07, 2018 at 08:24 AM 0
Share

I've edited the answer, hope this helps.

avatar image Chocolade cooldude5757 · Feb 07, 2018 at 09:30 AM 0
Share

Now it's working great. But I wonder what did you change ? I can see you added the line:

 lr.useWorldSpace = false;

And removed the line:

 myLine.transform.position = start;

Have I missed any other changes you did then my code ? I'm asking just for the knowledge to understand better :)

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

461 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 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 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

How do i change the GUI.Box font size and box size ? 0 Answers

How can i first destroy twice the objects then to create twice the objects ? 1 Answer

How can i rotate a transform using lerp but keep the nose in same direction/angle on x ? 1 Answer

To pass a variable between scenes should I use scriptableobject or static ? 1 Answer

How can i prevent from mouse to collide with thirdpersoncontroller ? 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