Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

freeze y position when ontriggerenter2d

Discussion in 'Scripting' started by verderveremem, Jun 2, 2014.

  1. verderveremem

    verderveremem

    Joined:
    May 11, 2014
    Posts:
    52
    hello folks,

    i want to freeze y position on my prefab and i wrote this code in update method:

    "kibrit" is my prefab, can u help me?


    GameObject Kibriting=Instantiate(kibrit, StartPoint, transform.rotation) as GameObject;



    Kibriting.transform.position= new Vector3(transform.position.x, -0.4175424f, 0);
     
  2. hektac

    hektac

    Joined:
    Nov 9, 2012
    Posts:
    28
    Is there a rigidbody on your object? If so you can lock the constraints once the object is instantiated:

    Code (CSharp):
    1. GameObject Kibriting = Instantiate(kibrit, StartPoint, transform.rotation) as GameObject;
    2. Kibriting.rigidbody.constraints = RigidbodyConstraints.FreezePositionY;
    See the scripting reference for more infomation: http://docs.unity3d.com/ScriptReference/Rigidbody-constraints.html
     
  3. verderveremem

    verderveremem

    Joined:
    May 11, 2014
    Posts:
    52

    thank you but i am using rigidbody2d, how can i editing this code for 2d?
     
  4. hektac

    hektac

    Joined:
    Nov 9, 2012
    Posts:
    28
    verderveremem likes this.
  5. verderveremem

    verderveremem

    Joined:
    May 11, 2014
    Posts:
    52

    thanks