I’m trying to make an object that the script is applied to look at an object that enters the radius of the trigger. I found something that is not making compile errors but the if statement doesn’t work because I seem to be referring to nothing. The line “transform.LookAt(obj.transform);” is mainly what I’m talking about.
public class AttractObject : MonoBehaviour
{
public GameObject attractionTo;//The the thing the script is applied to
private TagField CanBePulledByGrav;
public float strengthOfAttraction = 5.0f;
private Boolean GravRaidus;//The trigger collider
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter(Collider other)
{
Debug.Log("Object entered the trigger");
if (other.tag == "CanBePulledByGrav")
{
GameObject obj = GameObject.Find("CanBePulledByGrav");
transform.LookAt(obj.transform);
Debug.Log("If is working.");
}
}
void OnTriggerStay(Collider other)
{
//Debug.Log("Object is within trigger");
}
void OnTriggerExit(Collider other)
{
Debug.Log("Object exited the trigger");
}
}