unity change position relative to parent code example
Example 1: unity change position relative to parent
Use transform.localPosition instead of transform.position.
Works the same as transform.position if there is no parent.
Example :
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
void Example()
{
transform.localPosition = new Vector3(0, 0, 0);
print(transform.localPosition.y);
}
}
Example 2: transform object according to its parent unity
transform.localPosition = new Vector3(12.5f, 12.5f, 12.5f);