Jump to content
  • Advertisement
Sign in to follow this  
KitKat20152016

Unity Loading Screen in Unity3D in c#

This topic is 978 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to code a loading animation from this link http://projects.lukehaas.me/css-loaders/, the one I'm coding is the most top left corner(the 1 one), I code it up but it looks too complicated so I'm wondering does any one have a better solution , thanks :)

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

	float Timer;
	float Timer3;

	public float delayTime;
	public float dist;
	
	bool anim  = false;
	bool anim2 = false;
	float Timer5 = 0 ;
	// Use this for initialization
	void Start () {
		Timer = 0;
		Timer3 = delayTime;
	}
	
	// Update is called once per frame
	void Update () {

		if (anim == true) {
			//this Control the scale of the bar
			Timer += Time.deltaTime * 5;
			float a = Mathf.Sin (Timer); 
			Debug.Log(a);
			if (a < -0.95f) {
				anim2 = true;
			}
			if(anim2 == true){
				a = -1;
				//this control how long it will stop
				Timer5 -= Time.deltaTime;
				if(Timer5 < 0.0f){
					//reset the values so it can start the animation
					anim2 = false;
					Timer5 = 3.0f;
					Timer = 5f;
				}
			}
		this.transform.localScale = new Vector3 (this.transform.localScale.x, 0, a + 2);
		}else{
			//this control the delay of the image
			Timer3 -= Time.deltaTime;
			if (Timer3 < 0) {
				anim = true;
			}
		} 

	}
}

Edited by KitKat20152016

Share this post


Link to post
Share on other sites
Advertisement

You might want to look into animation clips?  Otherwise, if you want to do it through code, you might want to look into coroutines, I think it might make it cleaner. 

Edited by ferrous

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!