- Home /
Trying to add points.,
I know that the answer is going to be really easy. It is going to be something I missed for some reason. I am trying to get points by when the enemy dies. A public int goes up which is P goes up by 10 Then I get that int number by the get component script which updates the text box which is hooked up to the canvas. It goes and shows me a null value for some reason for every time I try to update it.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI;
public class PauseMenuScript : MonoBehaviour {
public static bool GameIsPaused = false;
public GameObject PausedMenuUI;
public Text HowToPause;
public Text Points;
public void Start()
{
Points.enabled = true;
HowToPause.enabled = true;
Destroy(HowToPause, 5f);
}
public void ExitGameFromWithInGame()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 2);
}
public void Update() // ask for help with the points.
{
Points.text = "Points" + GetComponent<Enemy>().P.ToString();
sing System.Collections; using System.Collections.Generic; using UnityEngine;
public class Enemy : MonoBehaviour {
public int health = 100;
public GameObject deathEffect;
public AudioSource Deathsound;
public int P = 0;
public int damage = 10;
public void TakeDamage(int damage)
{
health -= damage;
if (health <= 0)
{
Die();
}
}
// when health it at a certain mark. It dies and makes pretty things happen
public void Die()
{
Instantiate(deathEffect, transform.position, Quaternion.identity);
Deathsound.Play();
if (Deathsound.enabled == true)
{
P += 10; // adds points to the scirpt.
Destroy(gameObject);
}
}
},
Answer by dan_wipf · Nov 17, 2018 at 06:59 AM
do you destroy the points gameobject?
wel yes you do, might you want to reverse the ++points process so the counter will be in the paise menu script. because after points you imediatly destroy the gameobject where enemy script is
Besides this. $$anonymous$$ight I ask, what is your first language? Since it isn't English Just asking out of curiosity
naah it’s defently not ;D it’s swiss german
Answer by MKARSOTNEORS · Nov 17, 2018 at 07:16 AM
I don't destroy the points. Every time I try to use a get component script. It always came back as an error.
Your answer
Follow this Question
Related Questions
Ways to make OnMouseDown (or a single script) differentiate between different colliders/sprites 1 Answer
c# - List with multiple types - Trading Engine - Stock Simulator 2 Answers
variable not being changed outside of a method. [C#] 3 Answers
Trigger Sound more than Once 0 Answers
Setting a random animation frame from multiple animations 0 Answers