N
N
Nekit Medvedev2021-07-31 09:14:26
Unity
Nekit Medvedev, 2021-07-31 09:14:26

Why is the object that gets into the trigger not passed to the public field?

There is such a code, as a result, a reference to an object falling within the boundaries of the trigger should be transferred to the public target field, but this does not happen, why?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class IsTarget : MonoBehaviour
{
  public GameObject target;
  
    // Start is called before the first frame update
   
  private void OnTriggerEnter(Collider other)
    {
        target=other.gameObject;
     Debug.Log(target.name);
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Crebor, 2021-07-31
@Crebor

You are equating two gameobjects, which is fundamentally wrong.
You can get name = Debug.Log(other.gameObject.name);
And you can get it transform.position = Debug.Log(other.gameObject.transform.position);
Explain what goal you are pursuing, we will prompt.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question