Answer the question
In order to leave comments, you need to log in
NullReferenceException: Object reference not set to an instance of an object, why does it return null?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Sensor : MonoBehaviour
{
void Start()
{
}
void Update()
{
if (GetComponent<Fruit>().transform.position == GetComponent<Move>().transform.position)
{
Destroy(GetComponent<Fruit>().gameObject);
}
}
}
Answer the question
In order to leave comments, you need to log in
Well, you do not have all three components on the object Sensor
+ Fruit
+ Move
.
Then, even if they exist, their position will always be the same, because this is the same transform for all.
P.S. GetComponent
in Update
, yes, you should start with guides
Where's the error? And I realized that the 2nd script knocks out an error on line 26
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question