I'm creating a 2D in in Unity and I have a loading screen, that it's working (the loading animation). What I want to do next is to make the next screen appear (it's a gameobject), after a certain time. Right now, my code is:
public RectTransform mainIcon;
public float timeStep;
public float oneStepAngle;
float startTime;
// Start is called before the first frame update
void Start()
{
startTime = Time.time;
}
// Update is called once per frame
void Update()
{
if (Time.time - startTime >= timeStep) {
Vector3 iconAngle = mainIcon.localEulerAngles;
iconAngle.z = oneStepAngle;
mainIcon.localEulerAngles = iconAngle;
startTime = Time.time;
}
}
what should I do now? Thank you
CodePudding user response:
go to your game object that plays animation > create new script and ignore on start & update > Add this code
// object that would appear after animaton
public GameObject obj;
void showGameObject(){
objSetActive(true);
}
go back to your object that plays animation then add game object that will appear > go to animation controller on same object > select animation that our object will appear after > add animation event > in inspector you should have this > select function showGameObject
CodePudding user response:
You could use a simple timer like e.g.
public RectTransform mainIcon;
public float anglePerSecond = 90f;
public float duration;
public string nextScene;
private float timer;
// Update is called once per frame
void Update()
{
mainIcon.Rotate(Vector3.forward * anglePerSecond * Time.deltaTime);
timer = Time.deltaTime;
if(timer >= duration)
{
SceneManager.LoadScene(nextScene);
}
}