Null Refernce Error and Points duplicate
Hey I programm a 2D Endless Runner and want to pick up some coins but I get an Null Refernce Error at the OnTriggerEnter Methode. Also some Coins get 2 Points but should get 1 point. Thats the Error: NullReferenceException: Object reference not set to an instance of an object MünzenSammler.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/MünzenSammler.cs:28),Hey i have a big problem. i programm a 2D Endless Runner and i want to pick up some coins but i get an Null Reference Error in the OnTriggerEnter Methode. Also some Coins giving 2 points as 1 point.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class MünzenSammler : MonoBehaviour {
private int coinCounter;
public Text scoreText;
// Start is called before the first frame update
void Start()
{
coinCounter = 0;
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Coin")
{
coinCounter++;
Destroy (other.gameObject);
scoreText.text = "Score: " + coinCounter.ToString();
Debug.Log("Score: " + coinCounter);
}
}
}
,using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class MünzenSammler : MonoBehaviour {
private int coinCounter;
public Text scoreText;
// Start is called before the first frame update
void Start()
{
coinCounter = 0;
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Coin")
{
coinCounter++;
Destroy (other.gameObject);
scoreText.text = "Score: " + coinCounter.ToString();
Debug.Log("Score: " + coinCounter);
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613003523im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to have UI Manager come up on collision? 0 Answers
Player can only jump once!? 0 Answers
How Do I stop AI Following player on the Y-axis? 0 Answers
When i flip, the sprite moves 1 Answer
transform.localScal not flipping 0 Answers