- Home /
How many time does a prefab takes to load??
Hello everyone,
so I'm trying to change a couple of prefabs when mouse over/out them, and, I'm using this:
using UnityEngine;
using System.Collections;
public class zr_start : MonoBehaviour {
public GameObject btn_startOver;
void OnMouseEnter() {
Instantiate(btn_startOver, new Vector3(0,0,0), Quaternion.identity);
Destroy(this.gameObject);
}
}
and it do work but it have a 2 second delay to destroy the prefab and add the other one, it does not happen immediately, I was just wondering why that delay and if there's a way of get rid of that delay maybe???
any idea or help would be great!
Answer by whydoidoit · Feb 13, 2014 at 05:25 AM
Instantiation time depends on the complexity of your prefab.
The best plan is do not instantiate at run time make up a bunch of objects and enable/disable them when you want to create and destroy things - there are also several Assets on the store that will help you with this.
I guess that make sense, since I'm using ragetools svg component... gonna try disable/enable then, thanks!!
I've converted you "Answer" to a comment - on UA "Answer" means "Solution" and not "Reply" -> there's an "add new comment" button hidden on the right of the screen :)
Best of luck with it - if it works for you then tick the answer... Cheers :)
It worked!!!
I place both objects at same position just changing one level in the Z axis and use this for both objects:
first object which is at Vector3(0,0,0);
using UnityEngine;
using System.Collections;
public class zr_start : $$anonymous$$onoBehaviour {
private GameObject obj;
void Start() {
obj = GameObject.Find("btn_startOver");
}
void On$$anonymous$$ouseEnter() {
this.gameObject.SetActive(false);
obj.gameObject.SetActive(true);
}
}
second object which is at Vector3(0,0,1);
using UnityEngine;
using System.Collections;
public class zr_startOver : $$anonymous$$onoBehaviour {
private GameObject obj;
void Start() {
obj = GameObject.Find("btn_start");
}
void On$$anonymous$$ouseExit() {
this.gameObject.SetActive(false);
obj.gameObject.SetActive(true);
}
}
It looks as smooth as I wanted :)
thanks!!
Your answer
Follow this Question
Related Questions
Instantiating prefabs: "The object of type GameObject has been destroyed". 1 Answer
Accessing children of an instance doesn't work every time 1 Answer
Trouble with destroying an instantiated prefab 2 Answers
Check if object is destroyed on level load, if so instantiate prefab? 1 Answer
Can't remove instantiated prefab 0 Answers