This is my 1st scene. Animations are working fine.
I get this error when I take the character’s prefab and throw it into my 2nd scene. jumpblend keeps spinning and I can’t jump.
my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class playerkontrol : MonoBehaviour
{
private Rigidbody2D rb;
private Animator anim;
[SerializeField] private float speed;
[SerializeField] private float jumpForce;
[SerializeField] private Transform[] groundTransform;
[SerializeField] private float groundRadius;
[SerializeField] private LayerMask groundlayer;
[SerializeField] private float attackcooldown;
[SerializeField] private Collider2D attackCollider;
private bool attack;
private float attacktimer;
private bool grounded;
private bool facingRight;
public float zaman = 0;
public float can =10;
void Start()
{
facingRight = true;
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
attack = false;
attackCollider.enabled = false;
anim.SetBool("deadcheck", false);
if(SceneManager.GetActiveScene().buildIndex> PlayerPrefs.GetInt("kacincilevel"))
{
PlayerPrefs.SetInt("kacincilevel", SceneManager.GetActiveScene().buildIndex);
}
Time.timeScale = 1;
}
void Update()
{
Attack();
if (grounded && (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W)))
{
grounded = false;
anim.SetBool("groundcheck", grounded);
rb.AddForce(new Vector2(0, jumpForce));
}
}
void FixedUpdate()
{
grounded = isgrounded();
anim.SetBool("groundcheck", grounded);
anim.SetFloat("yAxisSpeed", rb.velocity.y);
float horizontal = Input.GetAxis("Horizontal");
Movement(horizontal);
Flip(horizontal);
if (can == 0)
{
anim.SetBool("deadcheck", true);
zaman += Time.deltaTime;
if (zaman > 1.05f)
{
Time.timeScale = 0;
}
}
}
void Movement(float horizontal)
{
rb.velocity = new Vector2(horizontal * speed, rb.velocity.y);
anim.SetFloat("speed",Mathf.Abs(horizontal));
}
void Flip(float horizontal)
{
if((horizontal > 0 && !facingRight) || (horizontal < 0 && facingRight))
{
facingRight = !facingRight;
transform.localScale = new Vector3(transform.localScale.x * -1, transform.localScale.y, transform.localScale.z);
}
}
private bool isgrounded()
{
if ( rb.velocity.y <= 0)
{
foreach (Transform trans in groundTransform)
{
Collider2D [] colliders = Physics2D.OverlapCircleAll(trans.position, groundRadius, groundlayer);
for(int i=0; i < colliders.Length; i++)
{
if ( colliders[i].gameObject!= gameObject)
{
return true;
}
}
}
}
return false;
}
private void Attack()
{
if (Input.GetKeyDown("z") && !attack && grounded)
{
anim.ResetTrigger("idle");
attack = true;
anim.SetTrigger("attack");
attacktimer = attackcooldown;
attackCollider.enabled = true;
}
if (attack)
{
if (attacktimer > 0)
{
attacktimer -= Time.deltaTime;
}
else
{
attack = false;
attackCollider.enabled = false;
}
}
}
void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == "sopa")
{
collision.GetComponent<mizrak>().enabled = true;
}
if (collision.gameObject.tag == "dead")
{
if (attackCollider.enabled)
{
can++;
}
else if(!attackCollider.enabled)
{
can = 0;
}
}
}
}