Having this Error that i can Find to fix look all over the Net,Assets/Enemy1.cs(37,35): error CS1612

I am trying to convert a java script to C# from 2012 and it seem to giving nasty error i it.
Assets/Enemy1.cs(37,35): error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position’. Consider storing the value in a temporary variable

using UnityEngine;
using System.Collections;

public class Enemy1 : MonoBehaviour {

    public float a;
    public float b;
    public float c;
    public float d;
    public float x3;
    public float x2;
    public float x1;
    public int path;
    public float xSpeed;
    public float ySpeed;


    CalcPosition calcPosition;

    public int dir;
    void Start () {
        xSpeed = 5;
        ySpeed = xSpeed;


    }


  
    // Update is called once per frame
    void Update () {
      

        calcPosition = GetComponent<CalcPosition> ();
        switch (path) {
        case 1:
            transform.position.x += dir * xSpeed * Time.deltaTime;
            transform.position.y = CalcPosition.Pos1(transform.position.x, a, x2, d);
            break;

        case 2:
            transform.position.x += dir* xSpeed * Time.deltaTime;
            transform.position.y = CalcPosition.Pos2 (transform.position.x, a, b, d);
            break;
        case 3:
            transform.position.y -=  ySpeed * Time.deltaTime;
            transform.position.x = CalcPosition.Pos3(transform.position.y, a, b, d);
            break;
        default:
            print ("Enemy1.cs: Update(): path out of range");
            break;
      
        }// switch (path)
  
    } // Update()


}

This is because Vector3 (the type of position) is a struct which is a value type not a reference, so you would be changing a copy of the field that is returned not the value itself. you can create a new vector3 and assign that, something like…

Vector3 newPosition = new Vector3();
newPosition.x += dir* xSpeed * Time.deltaTime;
newPosition.y = CalcPosition.Pos1(transform.position.x, a, x2, d);
transform.position = newPosition;

or possibly better to use Transform.Translate…

thanks bro it working but after finishing that having a next error in my waves script

it a space shooter game i making i i find a java script tutorial from since 2012 and the script is to make the enemy appear side of the screen in a snake movement!

There is a C# SpaceShooter tutorial on the learn section of the site if that helps :slight_smile:

dude i wan more from it i planning on selling the game so tutorial that there have is cheap