Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Instantly move or change rotation of object through C# script

Discussion in 'Scripting' started by Callski, Feb 3, 2013.

  1. Callski

    Callski

    Joined:
    Feb 3, 2013
    Posts:
    130
    I've been trying to figure out how to change a unity object's position and rotation without much luck. A quick example would be much appreciated!

    Code (csharp):
    1.  
    2. Vector3 position = cam.transform.position;
    3. plane.transform.position = position;
    4.  
    For whatever reason this creates a second plane instead of just changing the plane variable I already have.
     
  2. Callski

    Callski

    Joined:
    Feb 3, 2013
    Posts:
    130
    Sorry for wasting your time. I got it! I'm creating my objects through script so whenever I hit run it reads every object to the hierarchy. Now I just have to figure out how to make unity remove the objects after play.