/**
	 * 
	 */
	public void SetObstacleJumpInfo(LevelGenerator.JumpInfo jumpInfo)
	{
		#if UNITY_EDITOR
			if (mObstacleJumpInfo != null && jumpInfo != null) Debug.LogWarning("Already assigned");
		#endif

		mObstacleJumpInfo = jumpInfo;
	}
	/**
	 * 
	 */
	void FixedUpdate()
	{


		sPosition = mTransform.localPosition;

		if (sPosition.x < DiesAtMeters || DiesAtMeters == -1)
		{
			float speedPerFrame;
			speedPerFrame = mPlayer.CurrentSpeed * Time.fixedDeltaTime;
			sPosition.x += speedPerFrame;

			float ySpeed;
			if (mCurJumpInfo != null)
			{
				if (mCurJumpInfo.type == LevelGenerator.JumpType.Platform)
				{
					if (mObstacleJumpInfo != null)
					{
						if (mObstacleJumpInfo.jumpStart.x <= sPosition.x)
						{
							// Switch to obstacle jumping
							mGroundY = mCurJumpInfo.jumpEnd.y;
							mCurJumpInfo = mObstacleJumpInfo;
						}
					}
				}
				else
				{
					if (mPlatformJumpInfo != null)
					{
						if (mPlatformJumpInfo.jumpStart.x <= sPosition.x)
						{
							// Switch to platform jumping
							mGroundY = mCurJumpInfo.jumpEnd.y;
							mCurJumpInfo = mPlatformJumpInfo;
							mObstacleJumpInfo = null;
						}
					}
				}

				#if UNITY_EDITOR
				Debug.DrawLine(new Vector3(mCurJumpInfo.jumpStart.x, mCurJumpInfo.jumpPeak.y + 1, 0),
				               new Vector3(mCurJumpInfo.jumpEnd.x, mCurJumpInfo.jumpPeak.y + 1, 0));
				#endif

				if (sPosition.x >= mCurJumpInfo.jumpStart.x && sPosition.x <= mCurJumpInfo.jumpEnd.x)
				{
					// Jumping and descending

					mGroundY = float.MaxValue;
					ySpeed = mTransform.localPosition.x < mCurJumpInfo.jumpPeak.x ? JumpSpeed : Gravity;
					sPosition.y += Time.fixedDeltaTime * ySpeed;

					if (mCurrentAnimation != AnimationState.Jump || sPosition.x <= mCurJumpInfo.jumpStart.x)
					{
						mAnimator.Play("jump");
						mCurrentAnimation = AnimationState.Jump;
					}
				}
				else if (sPosition.x >= mCurJumpInfo.jumpEnd.x)
				{
					// Passed landing point

					if (mCurJumpInfo.type == LevelGenerator.JumpType.Platform)
					{
						mGroundY = mCurJumpInfo.jumpEnd.y;
						mCurJumpInfo = null;
						mCurPlatform = mNextPlatform;
						mObstacleJumpInfo = mCurPlatform.GetComponent<Platform>().obstacleJumpInfo;
						mNextPlatform = null;
						mPlatformJumpInfo = null;

					}
					else
					{
						mGroundY = mCurJumpInfo.jumpEnd.y;
						mCurJumpInfo = mPlatformJumpInfo;
						mObstacleJumpInfo = null;
					}
				}
			}
			else
			{
				int index = mLevelGenerator.GetPlatformIndex(mCurPlatform);
				mNextPlatform = mLevelGenerator.GetPlatformAt(index + 1);

				if (mNextPlatform != null)
				{
					mPlatformJumpInfo = mCurJumpInfo = mLevelGenerator.GetJumpInfo(index);
				}
			}

			if (mGroundY != float.MaxValue)
			{
				if (sPosition.y > mGroundY)
				{
					sPosition.y += Gravity * Time.fixedDeltaTime;
					
					if (sPosition.y <= mGroundY)
					{
						sPosition.y = mGroundY;
						
						if (mCurrentAnimation != AnimationState.Run)
						{
							mAnimator.Play("run");
							mCurrentAnimation = AnimationState.Run;
						}
					}
				}
				else if(sPosition.y < mGroundY)
				{
					sPosition.y += JumpSpeed * Time.fixedDeltaTime;
					
					if (sPosition.y >= mGroundY)
					{
						sPosition.y = mGroundY;
						
						if (mCurrentAnimation != AnimationState.Run)
						{
							mAnimator.Play("run");
							mCurrentAnimation = AnimationState.Run;
						}
					}
				}
			}

			mTransform.localPosition = sPosition;
		}
		else
		{
		//	print ("AboutToDieAboutToDieAboutToDie");


			if (mRigidBody.simulated)
			{
				//print ("1");
				sHelperVector2.Set(mPlayer.CurrentSpeed, Gravity);
				mRigidBody.velocity = sHelperVector2;
			}
			else
			{
			//	print ("2");
				mRigidBody.simulated = true;
				mRigidBody.gravityScale = 1;
				this.collider2D.enabled = true;
				mGroundY = float.MaxValue;
			}
		}

		if (mNameLabel != null) UpdateNameLabel();
	}
	/**
	 * 
	 */




	public void Reset(GameObject platform, string gender = null)
	{
		// Random gender
//		if (gender == null) {
//			if (Random.value < 0.5f) mAnimator.runtimeAnimatorController = Multires.GetAnimatorController(Config.instance.BoyAnimator);
//			else mAnimator.runtimeAnimatorController = Multires.GetAnimatorController(Config.instance.GirlAnimator);
//		}
//		else {
//			string animator = gender == "Girl" ? Config.instance.GirlAnimator : Config.instance.BoyAnimator;
//			mAnimator.runtimeAnimatorController = Multires.GetAnimatorController(animator);
//		}

		// Elections change
		mAnimator.runtimeAnimatorController = Multires.GetAnimatorController(LevelGenerator.ChosenCharecter);

		mCurPlatform = platform;
		mObstacleJumpInfo = mCurPlatform.GetComponent<Platform>().obstacleJumpInfo;

		mNextPlatform = null;
		mCurJumpInfo = null;
		mPlatformJumpInfo = null;
		mGroundY = platform.transform.localPosition.y + LevelGenerator.CharacterHalfHeight;
		mCurrentAnimation = AnimationState.Run;
		mAnimator.Play("run");
		mRigidBody.simulated = false;
		this.collider2D.enabled = true;
		this.enabled = true;
	}