[Question] Does my code have sense?

Hello guys, Im enjoying your course really :slight_smile: currently I am at Space defender moment, and I’ve done couple things alone, using my own methods. I wonder if it’s right, or I should do it like you in the course?

To destroy projectiles out of map I didn’t use your method with collidor, but code instead, and for the Score keeper I also did something little else. Can you tell me if it’s fine? Thanks

So part of my code destroys projectiles out of map :

Vector3 topdistancemax = 	Camera.main.ViewportToWorldPoint(new Vector3(0,1,distance));
ymax = topdistancemax.y;

foreach (Transform laser in GameObject.Find("Projectiles").transform){
	if (laser.position.y > ymax)
		{
			DestroyObject(laser.gameObject);
		}
}

Same for enemies but with (< ymin) instead.

And this is my score keeper :

Text hp,score;
public static int scorevalue;

	void Update () {
		UpdateHP();
		UpdateScore();
	}

	void UpdateHP(){
		hp = GameObject.Find("hp").GetComponent<Text>();
		if (PlayerShip.health > 0) {
			hp.text = "HP: "+PlayerShip.health;
		} else {hp.text = "HP: 0";}
	}

	void UpdateScore(){
		score = GameObject.Find("score").GetComponent<Text>();
		if (scorevalue > 0) {
			score.text = ""+ scorevalue;
		} else {score.text = "SCORE";}
	}

and in EnemyBehaviour :

missile.Hit();
hudManager.scorevalue+=100;

Thanks

Privacy & Terms