From the start of the game, when i start it up & run it, the frog will start jumping.
After it lands from jumping it will get lower & lower, like each time it jumps it pushes the ground it was on, before jumping, down by 0.2 & then lands on the new lower ground. If anyone knows why or could help me figure out why its doing this each time it jumps i would very much appreciate it.
Thank You.
O & here are some pics to understand what im talking about and my code for it.
pic 1 is beginning before first jump
pic 2 is now after about 15-20 jumps (3 left then 3 right)
now the script code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FrogScript : MonoBehaviour {
private Animator anim;
private bool animation_Started;
private bool animation_Finished;
private int jumpedTimes;
private bool jumpLeft = true;
private string coroutine_Name = "FrogJump";
public LayerMask playerLayer;
private GameObject player;
void Awake()
{
anim = GetComponent<Animator>();
}
// Use this for initialization
void Start () {
StartCoroutine(coroutine_Name);
player = GameObject.FindGameObjectWithTag(MyTags.PLAYER_TAG);
}
void Update()
{
if (Physics2D.OverlapCircle(transform.position, 0.5f, playerLayer))
{
player.GetComponent<PlayerDamage>().DealDamage();
}
}
void LateUpdate () {
if (animation_Finished && animation_Started)
{
animation_Started = false;
transform.parent.position = transform.position;
transform.localPosition = Vector3.zero;
}
}
IEnumerator FrogJump()
{
yield return new WaitForSeconds(Random.Range(1f, 4f));
animation_Started = true;
animation_Finished = false;
jumpedTimes++;
if (jumpLeft)
{
anim.Play("FrogJumpLeft");
} else {
anim.Play("FrogJumpRight");
}
StartCoroutine(coroutine_Name);
}
void AnimationFinished()
{
animation_Finished = true;
if (jumpLeft)
{
anim.Play("FrogIdleLeft");
} else
{
anim.Play("FrogIdleRight");
}
if (jumpedTimes == 3)
{
jumpedTimes = 0;
Vector3 tempScale = transform.localScale;
tempScale.x *= -1;
transform.localScale = tempScale;
jumpLeft = !jumpLeft;
}
}
}//class