Why can't I assign transform.position to a Vector3 object?

I am programming to make my objects have a ‘drag-and-drop’ behavior. When the mouse clicks on one, they drag, but the only difference is I want it to return to the original position when the user lets go of the mouse.

Here is my error:
//A field initializer cannot reference a non-static field, method, or property (UnityEngine.Component.transform)
//The type UnityEngine.Vector3 does not take in a constructor that only has one argument

Vector3 ogPosition = new Vector3(transform.position);  

In response to the errors; I thought transform.position is multiple arguments since it has x,y, and z values so I am not sure why it wouldn’t work. I’ve searched for answers regarding this issue, but have not found any accurate sources.

Here is the rest of my code:

using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;

public class Drag : MonoBehaviour
{
	Vector3 ogPosition = new Vector3(transform.position);

	float distance = 5.18f;
	void OnMouseDrag()
	{

		Vector3 mousePosition = new Vector3 (Input.mousePosition.x, Input.mousePosition.y, distance);
		Vector3 objPosition = Camera.main.ScreenToWorldPoint (mousePosition); 
		//Takes in Vector Argument transforms screen view to world view
		transform.position = objPosition;


	}
	void OnMouseUp() 
	{
		Debug.Log("Drag ended!");
		transform.position = ogPosition;
	}

	void FixedUpdate()
	{
		
	}

}

Thanks in advance!

Here’s an edit since I didn’t realize that it wasn’t in a method either.

To use ogPosition in multiple methods, you need to declare it and then set it at a later time. You can also use @getyour411’s answer as well inside of start()

public Vector3 ogPosition;

void start(){
     ogPosition = transform.position;
}

This has nothing to do with Unity. C# does not allow field initializers besides constants, constructors and static fields, because to access a non-static field (position in this case) you’d need the constructed object, but field initializers run before the constructor. So you can have

Vector3 myVector = new Vector3(0, 0, 0);

But you can’t have:

Vector3 myVector = new Vector3(transform.position.x, transform.position.y, transform.position.z);

That’s the reason for your first error. Note that this only applies to fields (that is, variables declared at the class level) and not local variables declared in functions.

As for the second, Vector3 has no constructor which takes another Vector3 as input. You don’t need it either, since Vector3 is a value type (read up on the differences between classes and structs in C#). What you can do to work around it, as @smnerat already showed, is to set the Vector3 at a later time, such as in Start().

Edit: If you have a hard time understanding my answer, it’ll probably be a good idea to start with a few C# tutorials and move on to Unity only when you have a better understanding of the language.

Vector3 ogPosition = new Vector3(transform.position.x, transform.position.y, transform.position.z);

You have to give the 3 arguments of tPos

if (transform.position = Vector3 (2, 0, 33))
{
transform.position = new Vector3(0, 0, 0);
}
is my code but i get the error message "non invokable member vector3 cannot be used as a method