Answers for "unity change position relative to parent"

C#
2

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()
    {
        // Move the object to the same position as the parent:
        transform.localPosition = new Vector3(0, 0, 0);

        // Get the y component of the position relative to the parent
        // and print it to the Console
        print(transform.localPosition.y);
    }
}
Posted by: Guest on February-06-2021
2

transform object according to its parent unity

transform.localPosition = new Vector3(12.5f, 12.5f, 12.5f);
Posted by: Guest on April-26-2020

Code answers related to "unity change position relative to parent"

C# Answers by Framework

Browse Popular Code Answers by Language