Search Unity

Unity seems to output random numbers as position?

Discussion in 'Scripting' started by petizero, Apr 13, 2020.

  1. petizero

    petizero

    Joined:
    Jan 1, 2019
    Posts:
    47
    Hey!

    Basically i have a script that sets the position of a gameobject to a set value (0.52) but when i run the script and the conditions check out it just outputs some number that i never told it to do. Any help?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class panelPositioner : MonoBehaviour
    6. {
    7.     public GameObject Panel;
    8.    
    9.  
    10.     void Start()
    11.     {
    12.         if (transform.position.y >= 30)
    13.         {
    14.             Panel.transform.position = new Vector3(Panel.transform.position.x, -0.52f, 0);
    15.         }
    16.  
    17.         if (transform.position.y <= 30)
    18.         {
    19.             Panel.transform.position = new Vector3(Panel.transform.position.x, 0.52f, 0);
    20.         }
    21.     }
    22.  
    23.  
    24.     void Update()
    25.     {
    26.        
    27.     }
    28. }
    And after that this happens whenever i test it. (Picture related)
     

    Attached Files:

    • Ooof.png
      Ooof.png
      File size:
      123.9 KB
      Views:
      317
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    It's really hard to tell what's going on in the screenshot you provided. Could you explain what we are looking at a little bit? Also note that the position you see in the inspector under an object's transform is the local position: the position of that object relative to its parent. so unless all of the object's parents in the hierarchy are at (0,0,0), it will not show the object's world position, which is what you are setting in your script.

    It would also be nice to see the inspector view for the object that the script you provided is attached to.
     
    Last edited: Apr 13, 2020
    petizero likes this.