Apologies if the formatting of this post isnt right, this is my first time posting (Any Tips Welcome!)
I am getting the following error message;
NullReferenceException: Object reference not set to an instance of an object
Delivery.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/Delivery.cs:31)
Below is my code;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Delivery : MonoBehaviour
{
[SerializeField] Color32 hasPackageColor = new Color32 (1, 1, 1, 1);
[SerializeField] Color32 noPackageColor = new Color32 (1, 1, 1, 1);
[SerializeField] float destroyDelay = 0.5f;
bool hasPackage;
SpriteRenderer spriteRenderer;
void start ()
{
spriteRenderer = GetComponent<SpriteRenderer>();
}
void OnCollisionEnter2D(Collision2D other)
{
Debug.Log("Smash!!");
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Package" && !hasPackage)
{
Debug.Log ("Package Collected!");
hasPackage = true;
spriteRenderer.color = hasPackageColor;
Destroy (other.gameObject, destroyDelay);
}
if (other.tag == "Customer" && hasPackage)
{
Debug.Log ("Package Delivered!");
hasPackage = false;
spriteRenderer.color = noPackageColor;
}
}
}
Can anyone help with this?
Many Thanks.