K
K
KraGen.Developer2021-09-23 21:08:00
Unity
KraGen.Developer, 2021-09-23 21:08:00

Creating object during touch with trigger?

Hello, in general, there is a prefab in which there are two triggers, the first one that stands at the beginning should create a clone of itself, for example, by +10 in X, the next prefab should be the same. And the second trigger deletes the current prefab. I’m fine with the second one, but now I’m worried about the first one, because before that my clones were created by the coroutine every 2 seconds, but due to the fact that there are quite a few objects in the prefab, performance drops rapidly after a short period of time. So the most productive solution would be to simply spawn a 10 x X prefab on contact with the trigger. From what you can use in the creation script, I still have this current

public GameObject Triger;
public GameObject GroundPrefab;
Vector3 pos;

   public void OnTriggerEnter(Collider other){
        if(other.tag == "Player"){
            pos = Triger.transform.position.x;
            pos +=34;
            GameObject newTube = Instantiate(GroundPrefab, new Vector3(pos,-7.23f,0f), Quaternion.identity);
        }
    }

Help me please.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
KraGen.Developer, 2021-09-24
@KraGenDeveloper

In general, I found a solution and it's really simple
You just need to convert Vector3.x to floatfloat pos = Triger.transform.position.x;

V
Vitaliy Antipin, 2021-09-24
@Stelette

It's not clear what exactly needs to be done. Spawn object on trigger? So in the code above you already spawn a clone. With what exactly to help?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question