Skip to content

Instantly share code, notes, and snippets.

@divide-by-zero
Created March 29, 2015 15:12
Show Gist options
  • Save divide-by-zero/f8f356f0f9788fdd7b41 to your computer and use it in GitHub Desktop.
Save divide-by-zero/f8f356f0f9788fdd7b41 to your computer and use it in GitHub Desktop.
public static class TransformExtension{
public static void SetPosition(this Transform t, float? x = null, float? y = null, float? z = null) {
var pos = t.transform.localPosition;
if (x.HasValue) pos.x = x.Value;
if (y.HasValue) pos.y = y.Value;
if (z.HasValue) pos.z = z.Value;
t.transform.localPosition = pos;
}
public static void AddPosition(this Transform t, float? x = null, float? y = null, float? z = null) {
var pos = t.transform.localPosition;
if (x.HasValue) pos.x += x.Value;
if (y.HasValue) pos.y += y.Value;
if (z.HasValue) pos.z += z.Value;
t.transform.localPosition = pos;
}
public static void SetAngle(this Transform t, float? x = null, float? y = null, float? z = null) {
var angle = t.transform.localRotation.eulerAngles;
if (x.HasValue) angle.x = x.Value;
if (y.HasValue) angle.y = y.Value;
if (z.HasValue) angle.z = z.Value;
t.transform.localRotation = Quaternion.Euler(angle);
}
public static void AddAngle(this Transform t, float? x = null, float? y = null, float? z = null) {
var angle = t.transform.localRotation.eulerAngles;
if (x.HasValue) angle.x += x.Value;
if (y.HasValue) angle.y += y.Value;
if (z.HasValue) angle.z += z.Value;
t.transform.localRotation = Quaternion.Euler(angle);
}
public static void SetScale(this Transform t, float? x = null, float? y = null, float? z = null) {
var scale = t.transform.localScale;
if (x.HasValue) scale.x = x.Value;
if (y.HasValue) scale.y = y.Value;
if (z.HasValue) scale.z = z.Value;
t.transform.localScale = scale;
}
public static void AddScale(this Transform t, float? x = null, float? y = null, float? z = null){
var scale = t.transform.localScale;
if (x.HasValue) scale.x += x.Value;
if (y.HasValue) scale.y += y.Value;
if (z.HasValue) scale.z += z.Value;
t.transform.localScale = scale;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment