I recently downloaded a proyect from the asset store and when I tested it, Unity threw this exception. Well, i didnt notice where the problem is. I have let the part of the code where i think the problem is.
Someone could help me? Thanks in advance.
NullReferenceException: Object reference not set to an instance of an object
Meteor.MagneticEffect () (at Assets/Game/Scripts/Controller/Meteor.cs:159)
Meteor.Update () (at Assets/Game/Scripts/Controller/Meteor.cs:71)
void Update ()
{
ModeSelect();
if (GameController.instance.isGameOver == false && sceneMode == SceneMode.gamePlay)
{
MagneticEffect();
}
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("PlayerAttract"))
{
shipTransform = other.transform;
magnetZone = true;
}
}
void OnTriggerExit2D(Collider2D other)
{
if (other.CompareTag("PlayerAttract") & looseMagnet)
magnetZone = false;
}
void MagneticEffect()
{
if (magnetZone)
{
Vector3 directionToShip = shipTransform.position - trans.position;
rigidBD.AddForce(directionToShip * magnetDirection * Time.deltaTime, ForceMode2D.Force);
}
}