Quantcast
Channel: Questions in topic: "javascripting"
Viewing all articles
Browse latest Browse all 105

score counter not working

$
0
0
well i have been trying to fix this problem for a few days now and i still can't find the problem. my score counter wont register. for some reason it wont make the connection from my controller script and enemy script to my UI text. here is my script for both and hopefully one of you clever people can help me out. enemy script: #pragma strict public var speed : int = -5; var ScoreValue : int; private var gameController : GameController; function Update () { GetComponent.().velocity.y = speed; GetComponent.().angularVelocity = Random.Range(-30, 30); Destroy(gameObject, 3); } function OnTriggerEnter2D(obj : Collider2D) { var name = obj.gameObject.name; // If it collided with a bullet if (name == "bullet(Clone)") { // Destroy itself (the enemy) Destroy(gameObject); // And destroy the bullet Destroy(obj.gameObject); gameController.AddScore (ScoreValue); } // If it collided with the spaceship if (name == "spaceship") { Destroy(gameObject); } } controller script: public var bullet : GameObject; var scoreText : UI.Text; private var Score : int; function start () { Score = 0; UpdateScore (); } function Update() { // Move the spaceship horizontally GetComponent.().velocity.x = Input.GetAxis("Horizontal") * 17; // X axis limits if (transform.position.x <= -5.5f) { transform.position = new Vector2(-5.5f, transform.position.y); }else if (transform.position.x >= 5.5f) transform.position = new Vector2(5.5f, transform.position.y); //When the spacebar is pressed if (Input.GetKeyDown("space")) { // Create a new bullet at "transforn.position" // Which is the currecnt position of the ship Instantiate(bullet, transform.position, Quaternion.identity); } } function AddScore (newScoreValue : int) { Score += newScoreValue; UpdateScore (); } function UpdateScore () { scoreText.text = "Score: " + Score; }

Viewing all articles
Browse latest Browse all 105

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>