- Home /
Transform override
How would i go around making a "new" standard transform.
Atm it looks like 123, 245, 886 in the editor. How would i do so unity make the funky number the standard "1,1,1".
You could mean either:
- You want to create an empty game object that exists at a specific position in which case: GameObject g = new GameObject(); g.transform.position = Vector3.one; 
- You want to create a new transform object; which won't work. 
- You want to normalize your transform so that your values are bounded inside of 0f - 1f in which case: Vector3 nPos = transform.position.normalized; 
There might be a fourth case but without more detail in your question it's hard to guess.
Answer by Loius · Feb 08, 2012 at 02:29 PM
For what purpose?
Build a static method like
class weirdtransform {
 public static transform( t : Transform ) : Transform {
  var x : Transform;
  x.rotation = t.rotation;
  x.position = t.position - Vector3(123,456,886);
  return x;
 }
}
And then never use transform calls directly from code again, instead of gameObject.Transform.anything, use weirdtransform.transform( gameObject.Transform ).anything
That said, you may want to rethink what you're doing. 1,1,1 is a very nice central location.
It seems likely to me that @bormeth wants to create a Vector3. Hopefully we'll get some more detail.
Answer by bormeth · Feb 08, 2012 at 02:41 PM
Hey :) i want to normalize the transformer when looking in the unity editor.
Answer by Matt-Downey · Apr 24, 2017 at 10:23 AM
This is my solution.
 public abstract class CustomComponent : Component
 {
     public new CustomTransform transform;
 }
   
 public class CustomTransform
 {   
     public Vector3 position
     {
         get
         {
             initialize_transform();
             return transform_reference.position;
         }
         set
         {
             initialize_transform();
             transform_reference.position = value;
             transform_reference.position.Normalize();
         }
     }
     private void initialize_transform()
     {
         if (transform_reference == null)
         {
             transform_reference = this.GetComponent<Transform>();
         }
     }
     
     Transform transform_reference;
 }
This strategy can be done with any class with Transform transform, but bear in mind that 1) You still have to change the Transform in CustomTransform and 2) Using a reference to the Component (rather than CustomComponent) will alter Transform (not CustomTransform). 
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                