Quantcast
Channel: Questions in topic: "build"
Viewing all articles
Browse latest Browse all 4084

Scripts working in Editor, but not in build

$
0
0
Everything works great in the editor, but as soon as I try it in the build, some of the controls don't work, such as the Jump mechanic using the spacebar. It also gives me the following error: "NullReferenceException: Object reference not set to an instance of an object Player.Update () (at Assets/Scripts/Player/Player.cs:44)". Please help me! This project is due in less than a week!! Here's the script that tracks the player's health and what not: { public Collision2D collision; GameObject playerObject; Collider2D player; Rigidbody2D player_rb; readonly AudioSource gg_player; [Header("Enemy Hook Config")] public Rigidbody2D nearestEnemy; public Transform nearestEnemyTransform; [Header("Health Tracking")] public HealthBar healthBar; public Slider healthSlider; public int maxHealth = 100; public int currentHealth; private void Start() { healthSlider = GetComponent(); // Get the nearest enemy transform and collider nearestEnemyTransform = FindObjectOfType().GetComponent(); nearestEnemy = GetComponent(); // Set player health data healthBar.SetMaxHealth(maxHealth); healthBar.SetHealth(currentHealth); currentHealth = maxHealth; } void Update() { if (collision.gameObject.CompareTag("Enemy")) { TakeDamage(10); } if (currentHealth <= 0) { KillPlayer(); } else { return; } } void KillPlayer() { SceneManager.LoadScene("GameOver"); } //public void OnCollisionEnter2D() //{ // if(collision.collider.gameObject.CompareTag("Enemy")) // { // TakeDamage(10); // } //} void TakeDamage(int damage) { currentHealth -= damage; healthBar.SetHealth(currentHealth); } }

Viewing all articles
Browse latest Browse all 4084

Trending Articles