Yes I know probably asked 100 times but non of the solutions I’ve found worked for me. Right now I’ve got my character to jump and to land properly, but the thing is every so often it goes right back to the grounded animations just because I hit the space bar not long enough and the script read that the character was grounded while he was moving upwards. My idea is just to delay the scripts reaction for a second but the WaitForSeconds(x) fix didn’t worked whatever way I tried. I dunno what it is with me and delays but they don’t like me, but clearly it mußt be a sure answer it is not like in Java where you need a big threadsleep thing you’ve gotta do with first building the new thread.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EzyScript : MonoBehaviour
{
Animator animator;
int jumpHash = Animator.StringToHash("Jump");
int doubleJumpHash = Animator.StringToHash("DoubleJump");
int groundedHash = Animator.StringToHash("GroundedTotally");
private bool Jumped = false; //checks if character jumps for doublejump animation
public float distToGrounded = 15.0f;
public LayerMask ground;
Transform tr;
// Use this for initialization
void Start()
{
animator = GetComponent<Animator>();
tr = transform;
}
//checks if character is grounded
bool IsGrounded()
{
return Physics.Raycast(transform.position, -Vector3.up, distToGrounded);
}
void LateUpdate()
{
if ((IsGrounded()) && Jumped)
{
animator.SetTrigger(groundedHash);
Jumped = false;
}
}
// Update is called once per frame
void Update()
{
float move = Input.GetAxis("Vertical");
animator.SetFloat("Speed", move);
if (Input.GetKeyDown(KeyCode.Space))
{
if (Jumped == false) //if character doesn't jump, it jumps
{
animator.SetTrigger(jumpHash);
animator.SetBool("Grounded", false);
Jumped = true;
}
else //if character jumped, performed the doublejump animation
{
animator.SetTrigger(doubleJumpHash);
//Jumped = false;
}
}
}
}