why isn't this working? C#

public float leftX = -9.25f;
	public float rightX = 9.25f;
	public float topZ = 6.0f;
	public float bottomZ = -6.0f;
        private Vector3 player;

void Update () {
	
		player = this.transform.position;
		
			if (player.x < leftX){
					
				player.x = rightX;	
				}
				
			if (player.x > rightX){
					
					player.x = leftX;
				}
			
			if (player.z > topZ){
					
					player.z = bottomZ;
				}
			
			if (player.z < bottomZ){
					
					player.z = bottomZ;
				}

just a guess but i think you may have reversed your < and > 's

You are modifying the variable player, not the actual transform. Ah on a second look. Do you really want to set it to bootomZ twice? I would have assumed topZ at least once.

This should work:

player = this.transform.position;

            if (player.x < leftX){  
                     transform.position.x = rightX;  
                }
            if (player.x > rightX){               
                    transform.position.x = leftX;
                }
            if (player.z > topZ){
                    transform.position.z = bottomZ;
                }
            if (player.z < bottomZ){
                    transform.position.z = topZ;
                }

if i do it like that i get:
Assets/UnityOsc/OSCDemoUnity.cs(41,36): error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position’. Consider storing the value in a temporary variable

so that’s why i made the vector3 player variable…?
if i use player.x = rightx and so on it doesn’t come in on the left when going offscreen on the right and such…? don’t see what i’m doing wrong here?

btw here’s the whole script it gets it’s data from a PD-extended patch with a bunch of sensors.

/* ButtonBox V1 OscDemo for Unity	         */
/* Jim Bollansée | jim@jimboproductions.be   */
/* Creative Commons Attr NonComm ShareAlike  */
/* MadFac 2011                               */

using UnityEngine;
using UnityOSC;

using System;
using System.Collections;
//using System.Collections.Generic;

public class OSCDemoUnity : MonoBehaviour {
	
	public float speed = 5.0f;
	public float speedIncrease = 1.0f;
	public int range = 180;
	public float leftX = -9.25f;
	public float rightX = 9.25f;
	public float topZ = 6.0f;
	public float bottomZ = -6.0f;
	private ServerLog ButtonBoxOSC;
	private float target;
	private Vector3 player;
	
	
	
	// Use this for initialization
	void Start () {
		OSCHandler.Instance.CreateServer("ButtonBox", 2000);
		target = this.transform.rotation.eulerAngles.y;
		
	}
	
	// Update is called once per frame
	void Update () {
	
		    player = this.transform.position;
     
                if (player.x < leftX){  
                         player.x = rightX;  
                    }
                if (player.x > rightX){              
                        player.x = leftX;
                    }
                if (player.z > topZ){
                        player.z = bottomZ;
                    }
                if (player.z < bottomZ){
                        player.z = topZ;
                    }
		
		OSCHandler.Instance.UpdateLogs();
		ButtonBoxOSC = OSCHandler.Instance.Servers["ButtonBox"];
		
		foreach(OSCPacket Packet in ButtonBoxOSC.packets){
			if (Packet.Address.Equals("/ButtonBox/Data")){
				int OscData = (int)Packet.Data[0];
				
				
	// Make it happen
				
				float NormalizedData = (float)(OscData/ 1023f * (range*2))-range;
				target = NormalizedData;
				Debug.Log(NormalizedData);
				transform.rotation = Quaternion.Euler(new Vector3(0, target, 0));
				
				
			}
			
		}
		
	
		
		/// Don't forget to clear the messages and logs!
		ButtonBoxOSC.packets.Clear();
		ButtonBoxOSC.log.Clear();
	}
	
	/*void OnCollisionEnter(Collision collision){
		
			speed = -speed;
		
		if (speed > 0)
			speed += speedIncrease;
		if (speed < 0)
			speed -= speedIncrease;
			
		
			
	}*/
	
	void FixedUpdate (){
		
		transform.Translate(Vector3.right * (Time.deltaTime * speed));
		
	}
}

edit: even this isn’t working…?

if (player.x < leftX){
player = new Vector3( rightX, 0, transform.position.z);
}

the original code was fine, the missing thing is that you assign player back to transform.position.
you can’t modify transform.position directly because Vector3 is a struct and transform.position a property, so you are not accessing the position for real, you are accessing a copy of the position which is not possible (or makes no sense as it would not be applied to transform.position in this case, the copy simply vanishes if you don’t assign it)

but it also doesn’t work if i assign player to the transform.position in void start?
how should i go about it then?
i come from javascript where a thing like this would be very easy.

edit: well i did it like this finally, but i still wonder why i can’t simply say

transform.position.x = rightX;

			if (transform.position.x < leftX){
					
				transform.position = new Vector3(rightX, 0, transform.position.z);	
				}
				
			if (transform.position.x > rightX){
					
				transform.position = new Vector3(leftX, 0, transform.position.z);
				}
			
			if (transform.position.z > topZ){
					
				transform.position = new Vector3(transform.position.x, 0, bottomZ);
				}
			
			if (player.z < bottomZ){
					
				transform.position = new Vector3(transform.position.x, 0, topZ);
				}