C# Jumping

Hello, I am verry new to Unity. I used GameMaker Studio (GML) for a few years, but C# is new to me. I am busy watching tutorials and adding some extra stuff to it myself to learn the language. But I am stuck. This is what I have:

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {
	private Vector3 input;



	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		input = new Vector3(Input.GetAxis ("Horizontal"),0,Input.GetAxis ("Vertical"));
		rigidbody.AddForce(input*20);
		if (Input.GetKey(KeyCode.Space))
		{
			transform.position.y += 40;
		}


	}
}

But when I try to run this I get an error that I cannot modify a value type return value of ‘UnityEngine.Transform.postion’.
How can I solve this? :face_with_spiral_eyes:

Vector3 temp = new Vector3(7.0f,0,0);
myGameObject.transform.position += temp;

or

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

Also you can use this

void SetTransformX(float n){

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

}

void Update (){

    SetTransformX(7.0f);

}

Hi,

I know have this:

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {



	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		transform.position = new Vector3(Input.GetAxis ("Horizontal"),0,Input.GetAxis ("Vertical"));
		if (Input.GetKey(KeyCode.Space))
		{
			transform.position.y += 40;
		}


	}
}

But I still get the same error?

Replace
transform.position.y += 40;
on
transform.position += new Vector3(0, 40, 0); :smile: