Hello everyone!
I have been trying to check the tag of the object my “score object” collides with.
I tried this:
using UnityEngine;
using System.Collections;
public class ScoreUpgrade : MonoBehaviour
{
public int score = 0;
void Start ()
{
this.GetComponent<OTSprite> ().onCollision = OnCollision;
}
public void OnCollision (OTObject owner)
{
if (owner.collision.gameObject.tag == "Player") {
GameObject.FindGameObjectWithTag ("ScriptHolder").GetComponent<Score> ().addScore (score);
GameObject.Destroy (this.gameObject);
}
}
}
But it seems to give me a NullReferenceException:
NullReferenceException: Object reference not set to an instance of an object
ScoreUpgrade.OnCollision (.OTObject owner) (at Assets/Scripts/Gameplay/Upgrades/ScoreUpgrade.cs:16)
OTObject.OnTriggerEnter (UnityEngine.Collider c) (at Assets/Standard Assets/OT/_Base/OTObject.cs:2212)
And i can’t figure out why
Thanks in advance!
- Frederik