When my player touches and object is triggered runs and I use.
Destroy(other.gameObject)
This Destroys the object. Is there another way to make this object disappear so it doesn’t effect my player movement and have it return after a few seconds or something like that?
You may try:
yourGameObject.setActive(false)
And when u need it back:
yourGameObject.setActive(true)
Like the others said, you can just use setActive, but if you want it to be activated after a while you can do the following:
void OnCollisionEnter (Collision other) {
// Disable
other.gameObject.setActive (false);
// Re-enable
StartCoroutine (SetActive (other, 5f));// set active after 5 seconds
}
Enumarator SetActive (Collision other, float seconds) {
// Wait for the specified time
yield return new WaitForSeconds (seconds);
// Set the object enabled again
other.gameObject.setActive (true);
}
You can use GameObject.SetActive to deactivate your gameobject rather than destroying it. Then you can activate the gameobject again to get it back.