Section 6 lecture 106

Hello @Rob hope you’re fine. :slight_smile:

There is a problem with spaceship, player in the game, it just not moving neither left or right. There is no error in the script i checked.

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

public class PlayerController : MonoBehaviour {
public float speed = 15.0f;
public float padding = 1f;
float xmin;
float xmax;

void start (){
	float distance = transform.position.z - Camera.main.transform.position.z;
	Vector3 leftmost = Camera.main.ViewportToWorldPoint(new Vector3(0,0,distance));
	Vector3 rightmost = Camera.main.ViewportToWorldPoint(new Vector3(1,0,distance));

	xmin = leftmost.x + padding;
	xmax = rightmost.x - padding;
}


void Update () {
	if (Input.GetKey(KeyCode.LeftArrow)){ 
		//transform.position += new Vector3(-speed *Time.deltaTime, 0 , 0);
		transform.position += Vector3.left  * speed * Time.deltaTime;

	}else if (Input.GetKey(KeyCode.RightArrow)){
		//transform.position += new Vector3(speed *Time.deltaTime, 0 , 0);
		transform.position += Vector3.right * speed * Time.deltaTime;

	}

	// restrict the player to the gamespace
	float newX = Mathf.Clamp(transform.position.x, xmin, xmax);
	transform.position = new Vector3(newX, transform.position.y, transform.position.z);
}

}

Hi @Sabeen_Moin,

Just to let you know I have seen your post, apologies for the delay, I have been AFK over the weekend. I will try to reslond properly this evening. If you get chance in between, if you could zip the project up and upload it for me that may save some time later. :slight_smile:


Updated Mon Jun 12 2017 16:57

Hold that…

Your Start() method has a lower case “s”, remember these are case sensitive so this needs to be an upper case “S”.

Change that, I have a feeling this may get you further :slight_smile:

1 Like

Its okey :slight_smile: thank you and that error came because of the lower s :sweat_smile:. But then i fixed it. As my laptop broke down and i will not be able to continue this course until it get fixed.
I have a question regarding this book series “Sam Teach Yourself in 24 hours” - c#,unity,unrealEngine,java and C++. I don’t know if these books are legit or worth it because i have to study all these stuff for my degree in GD and i have no idea what book should i purchase that could help me learn and understand. Thank you :slight_smile:

Privacy & Terms