Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Unity animator works fine in my 1st scene but not in my 2nd scene

Discussion in 'Animation' started by iProfH1zen, May 31, 2022.

  1. iProfH1zen

    iProfH1zen

    Joined:
    Apr 6, 2019
    Posts:
    2
    upload_2022-5-31_15-2-34.png
    This is my 1st scene. Animations are working fine.
    upload_2022-5-31_15-3-44.png
    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.
    upload_2022-5-31_15-5-44.png
    my code
    upload_2022-5-31_15-8-36.png
    upload_2022-5-31_15-9-0.png
     
  2. iProfH1zen

    iProfH1zen

    Joined:
    Apr 6, 2019
    Posts:
    2
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5. using UnityEngine.UI;
    6.  
    7. public class playerkontrol : MonoBehaviour
    8. {
    9.     private Rigidbody2D rb;
    10.     private Animator anim;
    11.     [SerializeField] private float speed;
    12.     [SerializeField] private float jumpForce;
    13.     [SerializeField] private Transform[] groundTransform;
    14.     [SerializeField] private float groundRadius;
    15.     [SerializeField] private LayerMask groundlayer;
    16.     [SerializeField] private float attackcooldown;
    17.     [SerializeField] private Collider2D attackCollider;
    18.  
    19.     private bool attack;
    20.     private float attacktimer;
    21.     private bool grounded;
    22.     private bool facingRight;
    23.     public float zaman = 0;
    24.     public float can =10;
    25.    
    26.  
    27.     void Start()
    28.     {
    29.         facingRight = true;
    30.         rb = GetComponent<Rigidbody2D>();
    31.         anim = GetComponent<Animator>();
    32.         attack = false;
    33.         attackCollider.enabled = false;
    34.         anim.SetBool("deadcheck", false);
    35.         if(SceneManager.GetActiveScene().buildIndex> PlayerPrefs.GetInt("kacincilevel"))
    36.         {
    37.             PlayerPrefs.SetInt("kacincilevel", SceneManager.GetActiveScene().buildIndex);
    38.         }
    39.        
    40.         Time.timeScale = 1;
    41.     }
    42.  
    43.     void Update()
    44.     {
    45.         Attack();
    46.  
    47.         if (grounded && (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W)))
    48.         {
    49.             grounded = false;
    50.             anim.SetBool("groundcheck", grounded);
    51.             rb.AddForce(new Vector2(0, jumpForce));
    52.         }
    53.        
    54.     }
    55.  
    56.     void FixedUpdate()
    57.     {
    58.         grounded = isgrounded();
    59.         anim.SetBool("groundcheck", grounded);
    60.         anim.SetFloat("yAxisSpeed", rb.velocity.y);
    61.         float horizontal = Input.GetAxis("Horizontal");
    62.         Movement(horizontal);
    63.         Flip(horizontal);
    64.         if (can == 0)
    65.         {
    66.             anim.SetBool("deadcheck", true);
    67.             zaman += Time.deltaTime;
    68.             if (zaman > 1.05f)
    69.             {
    70.                
    71.                 Time.timeScale = 0;
    72.             }
    73.         }
    74.        
    75.     }
    76.  
    77.     void Movement(float horizontal)
    78.     {
    79.  
    80.         rb.velocity = new Vector2(horizontal * speed, rb.velocity.y);
    81.         anim.SetFloat("speed",Mathf.Abs(horizontal));
    82.  
    83.      
    84.  
    85.     }
    86.  
    87.     void Flip(float horizontal)
    88.     {
    89.         if((horizontal > 0 && !facingRight) || (horizontal < 0 && facingRight))
    90.         {
    91.             facingRight = !facingRight;
    92.  
    93.             transform.localScale = new Vector3(transform.localScale.x * -1, transform.localScale.y, transform.localScale.z);
    94.         }
    95.     }
    96.  
    97.     private bool isgrounded()
    98.     {
    99.         if ( rb.velocity.y <= 0)
    100.         {
    101.             foreach (Transform trans in groundTransform)
    102.             {
    103.                 Collider2D [] colliders = Physics2D.OverlapCircleAll(trans.position, groundRadius, groundlayer);
    104.  
    105.                 for(int i=0; i < colliders.Length; i++)
    106.                 {
    107.                     if ( colliders[i].gameObject!= gameObject)
    108.                     {
    109.                         return true;
    110.                     }
    111.                 }
    112.             }
    113.         }
    114.         return false;
    115.     }
    116.     private void Attack()
    117.     {
    118.         if (Input.GetKeyDown("z") && !attack && grounded)
    119.         {
    120.             anim.ResetTrigger("idle");
    121.             attack = true;
    122.             anim.SetTrigger("attack");
    123.             attacktimer = attackcooldown;
    124.             attackCollider.enabled = true;
    125.         }
    126.         if (attack)
    127.         {
    128.             if (attacktimer > 0)
    129.             {
    130.                 attacktimer -= Time.deltaTime;
    131.             }
    132.             else
    133.             {
    134.                 attack = false;
    135.                 attackCollider.enabled = false;
    136.             }
    137.         }
    138.  
    139.  
    140.     }
    141.     void OnTriggerEnter2D(Collider2D collision)
    142.     {
    143.         if (collision.gameObject.tag == "sopa")
    144.         {
    145.             collision.GetComponent<mizrak>().enabled = true;
    146.  
    147.         }
    148.         if (collision.gameObject.tag == "dead")
    149.         {
    150.             if (attackCollider.enabled)
    151.             {
    152.                 can++;
    153.             }
    154.             else if(!attackCollider.enabled)
    155.             {
    156.                 can = 0;
    157.             }
    158.            
    159.  
    160.         }
    161.  
    162.     }
    163.    
    164.    
    165.  
    166.  
    167. }
    168.