- Home /
Error whit c# code 'UnityEngine.Transform.position' because it is not a variable.
hi I am develop in C# but I have a error with this
  Player01.position.x = mainCam.ScreenToWorldPoint(new Vector3(75f, 0f, 0f)).x;
  Player02.position.x = mainCam.ScreenToWorldPoint(new Vector3(Screen.width - 75f, 0f, 0f)).x;
in the 2 lines, those is the messages of error:
Assets/GameSetup.cs(36,5): error CS0165: Use of unassigned local variable
Player01' Assets/GameSetup.cs(36,5): error CS0165: Use of unassigned local variablePlayer02'
and
Cannot modify the return value of 'UnityEngine.Transform.position' because it is not a variable.
this is all script:
 using UnityEngine;
 using System.Collections;
 
 
 public class GameSetup : MonoBehaviour
 {
     //Reference the camera
     public Camera mainCam;
 
     //Reference the colliders we are going to adjust
     public BoxCollider2D topWall;
     public BoxCollider2D bottomWall;
     public BoxCollider2D leftWall;
     public BoxCollider2D rightWall;
     //Reference the players
     public Transform Player01;
     public Transform Player02;
 
     void start() 
     {
         //Only set this to Update if you know the screen size can change during a playsession.
 
         //Move each wall to its edge location:
         topWall.size = new Vector2(mainCam.ScreenToWorldPoint(new Vector3(Screen.width * 2f, 0f, 0f)).x, 1);
         topWall.center = new Vector2(0f, mainCam.ScreenToWorldPoint(new Vector3(0f, Screen.height, 0f)).y + 0.5f);
 
         bottomWall.size = new Vector2(mainCam.ScreenToWorldPoint(new Vector3(Screen.width * 2f, 0f, 0f)).x, 1f);
         bottomWall.center = new Vector2(0f, mainCam.ScreenToWorldPoint(new Vector3(0f, 0f, 0f)).y - 0.5f);
 
         leftWall.size = new Vector2(1f, mainCam.ScreenToWorldPoint(new Vector3(0f, Screen.height * 2f, 0f)).y); ;
         leftWall.center = new Vector2(mainCam.ScreenToWorldPoint(new Vector3(0f, 0f, 0f)).x - 0.5f, 0f);
 
         rightWall.size = new Vector2(1f, mainCam.ScreenToWorldPoint(new Vector3(0f, Screen.height * 2f, 0f)).y);
         rightWall.center = new Vector2(mainCam.ScreenToWorldPoint(new Vector3(Screen.width, 0f, 0f)).x + 0.5f, 0f);
 
 
         //Move the players to a fixed distance from the edges of the screen:
         Player01.position.x = mainCam.ScreenToWorldPoint(new Vector3(75f, 0f, 0f)).x;
         Player02.position.x = mainCam.ScreenToWorldPoint(new Vector3(Screen.width - 75f, 0f, 0f)).x;
 
     }
 }
 
this is that I want getting:

               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by zharik86 · Oct 09, 2014 at 07:05 PM
In CSharp you can't modify elements of position by one. Create another Vector3. Example see bellow:
  Vector3 tempVec = Vector3.zero;
  tempVect = Player01.position;
  tempVec.x = mainCam.ScreenToWorldPoint(new Vector3(75f, 0f, 0f)).x;
  Player01.position = tempVec;
  tempVect = Player02.position;
  tempVec.x = mainCam.ScreenToWorldPoint(new Vector3(Screen.width - 75f, 0f, 0f)).x;
  Player02.position = tempVec;
I he that it will help you.
is fine dont giveme any error but dont work in my execize
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                