My "if" statement doesn't work?

Hi there, i am new to the community an am trying to write a bit of code for an online lesson! so far i have managed to fix pretty much all of my errors i just can’t figure this one out. Could someone tell me where about i am going wrong please?

here is the code:

void Start () {
	
}

// Update is called once per frame
void Update (){
	var rigidbody =
		GetComponent<Rigidbody2D> ();
	var transform =
		GetComponent<Transform> ();
          if (transform.position.y < -6) {
		 (transform.position = new Vector2
			(-5,2)
		)
		if (Input.GetKey ("right")) {
			rigidbody.velocity = new Vector2 (5, 0);
	Debug.Log ("The right arrow was pressed");
}

	if (Input.GetKey ("left")) {
			rigidbody.velocity = new Vector2 (-5, 0);
		Debug.Log ("The left arrow was pressed");
	}             
	if (Input.GetKey ("space")) {
		rigidbody.velocity = new Vector2 (0, 5);
				Debug.Log ("The space button was pressed");
			}
		}
	}
}

Thank you, i appreciate anyone response. Sorry if its really simple ;-;

void Update ()
{
var rigidbody = GetComponent ();
var transform = GetComponent ();

     if (transform.position.y < -6) 
     {
          (transform.position = new Vector2(-5, 2))
         
          if (Input.GetKey ("right")) 
          {
               rigidbody.velocity = new Vector2 (5, 0);
          
               Debug.Log ("The right arrow was pressed");
          }
     
          if (Input.GetKey ("left")) 
          {
               rigidbody.velocity = new Vector2 (-5, 0);
               Debug.Log ("The left arrow was pressed");
          }             
     
          if (Input.GetKey ("space")) 
          {
               rigidbody.velocity = new Vector2 (0, 5);
               Debug.Log ("The space button was pressed");
          }
     }
}

Sorry, I couldn’t read it correctly using the way you wrote it. Anyway, looking at it (and I copied exactly as you wrote), it seems that right after you do the comparison “transform.position.y < -6f” you do “(transform.position = new Vector2(-5,2))”… But this is not correct. First of all, don’t use parenthesis on an entire line, and you also forgot about the ; at the end of the line.

So basically you need to do:
transform.position = new Vector2(-5, 2);


As a good practice advice, avoid declaring variables and using GetComponent<> inside of the Update function, it may cause problems of performance. Besides, transform is already accessible through script without you needing to declare and access the component manually, so the better version of this would be:

var rigidbody;

void Start()
{
     rigidbody = GetComponent<RigidBody>();
}