K
K
Kotaro Hiba2020-05-04 04:09:06
Unity
Kotaro Hiba, 2020-05-04 04:09:06

Why is the object created with scripts disabled, even though everything is enabled in the prefab?

Just started learning Unity, here is the code.
As soon as the cube reaches a certain mark, it is removed and the same cube is created.
I put the prefab in mems.
The problem is, as soon as the initial cube is deleted, a new cube is generated, but all the scripts that are attached are not active, what's wrong?

public class LiveObject : MonoBehaviour
{
    private Transform _transform;
    public GameObject mems;
    void Start()
    {
        _transform = GetComponent<Transform>();
    }

    void Update()
    {
        print(_transform.position.y);
        if (_transform.position.y < -4f)
        {
            Destroy(gameObject);
            Instantiate(mems, new Vector2(0,0),  Quaternion.identity);
        }
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question