Error Unityengine.Transform does not contain a definition for 'position' [Unity 5.6]

Following the video step by step I would continuously receive an error

" Unityengine.Transform does not contain a definition for ‘position’"

the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour {

public float speed = 15.0f;

float xmin = -5;
float xmax = 5;

// Update is called once per frame
void Update () {
	if (Input.GetKey (KeyCode.LeftArrow)) {
		//this does the same thing
		//transform.position += new Vector3 (-speed * Time.deltaTime, 0, 0);
		transform.position += Vector3.left * speed * Time.deltaTime;
	} else if (Input.GetKey (KeyCode.RightArrow)) {
		//does the same thing
		//transform.position += new Vector3 (speed * Time.deltaTime, 0, 0);
		transform.position += Vector3.right * speed * Time.deltaTime;
	}
	
	//restricts Fighter to gamespace
	float newX = Mathf.Clamp(transform.postion.x, xmin, xmax);
	transform.position = new Vector3(newX, transform.position.y, transform.position.z);
	
}

}

So with a little bit backtracking into the Brick Breaker clone I grabbed code from the paddle.cs. This is my fighter.cs (player.cs in the tutorial) and it does what i assume the other code should have done.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour {

public float speed = 15.0f;

public float xmin = -5;
public float xmax = 5;

// Update is called once per frame
void Update () {
	if (Input.GetKey (KeyCode.LeftArrow)) {
		//this does the same thing
		//transform.position += new Vector3 (-speed * Time.deltaTime, 0, 0);
		transform.position += Vector3.left * speed * Time.deltaTime;
	} else if (Input.GetKey (KeyCode.RightArrow)) {
		//does the same thing
		//transform.position += new Vector3 (speed * Time.deltaTime, 0, 0);
		transform.position += Vector3.right * speed * Time.deltaTime;
	}
	
	//restricts Fighter to gamespace
	//float newX = Mathf.Clamp(transform.postion.x, xmin, xmax);
	//transform.position = new Vector3(newX, transform.position.y, transform.position.z);
	Vector3 fighterPos = new Vector3(0.5f, this.transform.position.y, -1f);
	fighterPos.x = Mathf.Clamp(transform.position.x, xmin, xmax);
	this.transform.position = fighterPos;
}

}

I hope to learn how to get the lesson code to work as well. But if someone could help explain why this code also works in it’s place. Also I would like to learn how to move things in blocks so everything is snappy if anybody has insite on that as well

-Will1

Privacy & Terms