Forum begins after the advertisement:


Error after add Destroy Animation Script at slash effect

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity Error after add Destroy Animation Script at slash effect

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #16181
    Pool ForReal
    Level 4
    Participant
    Helpful?
    Up
    0
    ::

    the error happen after i add destroy animation script at slash effect and when i klik its error

    View post on imgur.com
    #16182
    pepecry
    Level 7
    Participant
    Helpful?
    Up
    0
    ::

    Could be because of the Destroy script or in your take damage function. U should post your code here so the expert could support you faster

    #16183
    Pool ForReal
    Level 4
    Participant
    Helpful?
    Up
    0
    ::

    this my destroy animation

    <code>using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class DestroyAfterAnimation : MonoBehaviour
    {
        // Start is called before the first frame update
        void Start()
        {
            Destroy(gameObject, GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).length);
        }
    }</code>

    this my control code

    <code>using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class PlayerController : MonoBehaviour
    {
        [Header("Horizontal Movement Settings:")]
        [SerializeField] private float walkSpeed = 1;
        [Space(5)]
    
        [Header("Vertical Movement Settings")]
        [SerializeField] private float jumpForce = 45f;
        private float jumpBufferCounter;
        [SerializeField] private float jumpBufferFrames;
        private float coyoteTimeCounter = 0;
        [SerializeField] private float coyoteTime;
        private int airJumpCounter = 0;
        [SerializeField] private int maxAirJumps;
        [Space(5)]
    
        [Header("Ground Check Settings:")]
        [SerializeField] private Transform groundCheckPoint;
        [SerializeField] private float groundCheckY = 0.2f;
        [SerializeField] private float groundCheckX = 0.5f;
        [SerializeField] private LayerMask whatIsGround;
        [Space(5)]
    
        [Header("Dash Settings")]
        [SerializeField] private float dashSpeed;
        [SerializeField] private float dashTime;
        [SerializeField] private float dashCooldown;
        [SerializeField] GameObject dashEffect;
        [Space(5)]
    
        [Header("Attacking")]
        bool attack = false;
        float timeBetweenAttack, timeSinceAttack;
        [SerializeField] private Transform SideAttackTransform, UpAttackTransform, DownAttackTransform;
        [SerializeField] private Vector2 SideAttackArea, UpAttackArea, DownAttackArea;
        [SerializeField] private LayerMask AttackableLayer;
        [SerializeField] float damage;
        [SerializeField] GameObject slashEffect;
    
        PlayerStateList pState;
        private Rigidbody2D rb;
        private float xAxis,yAxis;
        private float gravity;
        Animator anim;
        private bool canDash = true;
        private bool dashed;
    
    
    
        public static PlayerController Instance;
    
        private void Awake()
        {
            if (Instance != null && Instance != this)
            {
                Destroy(gameObject);
            }
            else
            {
                Instance = this;
            }
        }
    
        // Start is called before the first frame update
        void Start()
        {
            pState = GetComponent<PlayerStateList>();
    
            rb = GetComponent<Rigidbody2D>();
    
            anim = GetComponent<Animator>();
    
            gravity = rb.gravityScale;
        }
    
        private void OnDrawGizmos()
        {
            Gizmos.color = Color.red;
            Gizmos.DrawWireCube(SideAttackTransform.position, SideAttackArea);
            Gizmos.DrawWireCube(UpAttackTransform.position, UpAttackArea);
            Gizmos.DrawWireCube(DownAttackTransform.position, DownAttackArea);
        }
    
        // Update is called once per frame
        void Update()
        {
            GetInputs();
            UpdateJumpVariables(); 
    
            if (pState.dashing) return; 
            Move();
            Jump();
            Flip();
            StartDash();
            Attack();
        }
    
        void GetInputs()
        {
            xAxis = Input.GetAxisRaw("Horizontal");
            yAxis = Input.GetAxisRaw("Vertical");
            attack = Input.GetMouseButtonDown(0);
        }
    
        void Flip()
        {
            if (xAxis < 0)
            {
                transform.localScale = new Vector2(-Mathf.Abs(transform.localScale.x), transform.localScale.y);
            }
            else if (xAxis > 0)
            {
                transform.localScale = new Vector2(Mathf.Abs(transform.localScale.x), transform.localScale.y);
            }
        }
    
        private void Move()
        {
            rb.velocity = new Vector2(walkSpeed * xAxis, rb.velocity.y);
            anim.SetBool("Walking", rb.velocity.x != 0 && Grounded());
        }
    
        void StartDash()
        {
            if(Input.GetButtonDown("Dash") && canDash && !dashed)
            {
                StartCoroutine(Dash());
                dashed = true;
            }
    
            if(Grounded())
            {
                dashed = false;
            }
        }
    
        IEnumerator Dash()
        {
            canDash = false;
            pState.dashing = true;
            anim.SetTrigger("Dashing");
            rb.gravityScale = 0;
            rb.velocity = new Vector2(transform.localScale.x * dashSpeed, 0);
            if (Grounded()) Instantiate(dashEffect, transform);
            yield return new WaitForSeconds(dashTime);
            rb.gravityScale = gravity;
            pState.dashing = false;
            yield return new WaitForSeconds(dashCooldown);
            canDash = true;
        }
    
        void Attack()
        {
            timeSinceAttack += Time.deltaTime;
            if(attack && timeSinceAttack >= timeBetweenAttack)
            {
                timeSinceAttack = 0;
                anim.SetTrigger("Attacking");
    
                if(yAxis == 0 || yAxis < 0 && Grounded())
                {
                    Hit(SideAttackTransform, SideAttackArea);
                    Instantiate(slashEffect, SideAttackTransform);
                }
                else if (yAxis > 0)
                {
                    Hit(UpAttackTransform, UpAttackArea);
                    SlashEffectAngle(slashEffect, 80, UpAttackTransform);
                }
                else if (yAxis < 0 && !Grounded())
                {
                    Hit(DownAttackTransform, DownAttackArea);
                    SlashEffectAngle(slashEffect, -90, DownAttackTransform);
                }
            }
        }
    
        void Hit(Transform _attackTransform, Vector2 _attackArea)
        {
            Collider2D[] objectsToHit = Physics2D.OverlapBoxAll(_attackTransform.position, _attackArea, 0, AttackableLayer);
    
            if(objectsToHit.Length > 0 )
            {
                Debug.Log("Hit");
            }
            for (int i = 0; i < objectsToHit.Length; i++)   
            {
                if (objectsToHit[i].GetComponent<Enemy>() != null)
                {
                    objectsToHit[i].GetComponent<Enemy>().EnemyHit(damage);
                }
            }
        }
    
        void SlashEffectAngle(GameObject _slashEffect, int _effectAngle, Transform _attackTransform)
        {
            _slashEffect = Instantiate(_slashEffect, _attackTransform);
            _slashEffect.transform.eulerAngles = new Vector3(0, 0, _effectAngle);
            _slashEffect.transform.localScale = new Vector2(transform.localScale.x, transform.localScale.y);
        }
    
        public bool Grounded()
        {
            if (Physics2D.Raycast(groundCheckPoint.position, Vector2.down, groundCheckY, whatIsGround)
                || Physics2D.Raycast(groundCheckPoint.position + new Vector3(groundCheckX, 0, 0), Vector2.down, groundCheckY, whatIsGround)
                || Physics2D.Raycast(groundCheckPoint.position + new Vector3(-groundCheckX, 0, 0), Vector2.down, groundCheckY, whatIsGround))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    
        void Jump()
        {
            if (Input.GetButtonUp("Jump") && rb.velocity.y > 0)
            {
                rb.velocity = new Vector2(rb.velocity.x, 0);
    
                pState.jumping = false;
            }
             if (!pState.jumping)
            {
                if (jumpBufferCounter > 0 && coyoteTimeCounter > 0)
                {
                    rb.velocity = new Vector3(rb.velocity.x, jumpForce);
    
                    pState.jumping = true;
                }
                else if (!Grounded() && airJumpCounter < maxAirJumps && Input.GetButtonDown("Jump"))
                {
                    pState.jumping = true;
    
                    airJumpCounter++;
    
                    rb.velocity = new Vector3(rb.velocity.x, jumpForce);
                }
            }
    
    
            anim.SetBool("Jumping", !Grounded());
        }
    
        void UpdateJumpVariables()
        {
            if (Grounded())
            {
                pState.jumping = false;
                coyoteTimeCounter = coyoteTime;
                airJumpCounter = 0;
            }
            else
            {
                coyoteTimeCounter -= Time.deltaTime;
            }
    
            if (Input.GetButtonDown("Jump"))
            {
                jumpBufferCounter = jumpBufferFrames;
            }
            else
            {
                jumpBufferCounter = jumpBufferCounter - Time.deltaTime * 10;
            }
        }
    }</code>
    #16184
    pepecry
    Level 7
    Participant
    Helpful?
    Up
    0
    ::

    Try using this button when you enter your code to format it for the better vision

    Code button
    #16185
    Pool ForReal
    Level 4
    Participant
    Helpful?
    Up
    0
    ::

    where i can get it? because in my screen the image like loading image

    #16187
    pepecry
    Level 7
    Participant
    Helpful?
    Up
    0
    ::

    when enter your message. Look up a litte bit you will see something like B, I, IMG UL and CODE. CLick on the code to start format your message when input your code here. Then click it again to close it. It will look like this

    <code>using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class PlayerController : MonoBehaviour
    {
    [Header(“Horizontal Movement Settings:”)]
    [SerializeField] private float walkSpeed = 1;
    [Space(5)]
    
    [Header(“Vertical Movement Settings”)]
    [SerializeField] private float jumpForce = 45f;
    private float jumpBufferCounter;
    [SerializeField] private float jumpBufferFrames;
    private float coyoteTimeCounter = 0;
    [SerializeField] private float coyoteTime;
    private int airJumpCounter = 0;
    [SerializeField] private int maxAirJumps;
    [Space(5)]
    
    [Header(“Ground Check Settings:”)]
    [SerializeField] private Transform groundCheckPoint;
    [SerializeField] private float groundCheckY = 0.2f;
    [SerializeField] private float groundCheckX = 0.5f;
    [SerializeField] private LayerMask whatIsGround;
    [Space(5)]
    
    [Header(“Dash Settings”)]
    [SerializeField] private float dashSpeed;
    [SerializeField] private float dashTime;
    [SerializeField] private float dashCooldown;
    [SerializeField] GameObject dashEffect;
    [Space(5)]
    
    [Header(“Attacking”)]
    bool attack = false;
    float timeBetweenAttack, timeSinceAttack;
    [SerializeField] private Transform SideAttackTransform, UpAttackTransform, DownAttackTransform;
    [SerializeField] private Vector2 SideAttackArea, UpAttackArea, DownAttackArea;
    [SerializeField] private LayerMask AttackableLayer;
    [SerializeField] float damage;
    [SerializeField] GameObject slashEffect;
    
    PlayerStateList pState;
    private Rigidbody2D rb;
    private float xAxis,yAxis;
    private float gravity;
    Animator anim;
    private bool canDash = true;
    private bool dashed;
    
    public static PlayerController Instance;
    
    private void Awake()
    {
    if (Instance != null && Instance != this)
    {
    Destroy(gameObject);
    }
    else
    {
    Instance = this;
    }
    }
    
    // Start is called before the first frame update
    void Start()
    {
    pState = GetComponent<PlayerStateList>();
    
    rb = GetComponent<Rigidbody2D>();
    
    anim = GetComponent<Animator>();
    
    gravity = rb.gravityScale;
    }
    
    private void OnDrawGizmos()
    {
    Gizmos.color = Color.red;
    Gizmos.DrawWireCube(SideAttackTransform.position, SideAttackArea);
    Gizmos.DrawWireCube(UpAttackTransform.position, UpAttackArea);
    Gizmos.DrawWireCube(DownAttackTransform.position, DownAttackArea);
    }
    
    // Update is called once per frame
    void Update()
    {
    GetInputs();
    UpdateJumpVariables();
    
    if (pState.dashing) return;
    Move();
    Jump();
    Flip();
    StartDash();
    Attack();
    }
    
    void GetInputs()
    {
    xAxis = Input.GetAxisRaw(“Horizontal”);
    yAxis = Input.GetAxisRaw(“Vertical”);
    attack = Input.GetMouseButtonDown(0);
    }
    
    void Flip()
    {
    if (xAxis < 0)
    {
    transform.localScale = new Vector2(-Mathf.Abs(transform.localScale.x), transform.localScale.y);
    }
    else if (xAxis > 0)
    {
    transform.localScale = new Vector2(Mathf.Abs(transform.localScale.x), transform.localScale.y);
    }
    }
    
    private void Move()
    {
    rb.velocity = new Vector2(walkSpeed * xAxis, rb.velocity.y);
    anim.SetBool(“Walking”, rb.velocity.x != 0 && Grounded());
    }
    
    void StartDash()
    {
    if(Input.GetButtonDown(“Dash”) && canDash && !dashed)
    {
    StartCoroutine(Dash());
    dashed = true;
    }
    
    if(Grounded())
    {
    dashed = false;
    }
    }
    
    IEnumerator Dash()
    {
    canDash = false;
    pState.dashing = true;
    anim.SetTrigger(“Dashing”);
    rb.gravityScale = 0;
    rb.velocity = new Vector2(transform.localScale.x * dashSpeed, 0);
    if (Grounded()) Instantiate(dashEffect, transform);
    yield return new WaitForSeconds(dashTime);
    rb.gravityScale = gravity;
    pState.dashing = false;
    yield return new WaitForSeconds(dashCooldown);
    canDash = true;
    }
    
    void Attack()
    {
    timeSinceAttack += Time.deltaTime;
    if(attack && timeSinceAttack >= timeBetweenAttack)
    {
    timeSinceAttack = 0;
    anim.SetTrigger(“Attacking”);
    
    if(yAxis == 0 || yAxis < 0 && Grounded())
    {
    Hit(SideAttackTransform, SideAttackArea);
    Instantiate(slashEffect, SideAttackTransform);
    }
    else if (yAxis > 0)
    {
    Hit(UpAttackTransform, UpAttackArea);
    SlashEffectAngle(slashEffect, 80, UpAttackTransform);
    }
    else if (yAxis < 0 && !Grounded())
    {
    Hit(DownAttackTransform, DownAttackArea);
    SlashEffectAngle(slashEffect, -90, DownAttackTransform);
    }
    }
    }
    
    void Hit(Transform _attackTransform, Vector2 _attackArea)
    {
    Collider2D[] objectsToHit = Physics2D.OverlapBoxAll(_attackTransform.position, _attackArea, 0, AttackableLayer);
    
    if(objectsToHit.Length > 0 )
    {
    Debug.Log(“Hit”);
    }
    for (int i = 0; i < objectsToHit.Length; i++)
    {
    if (objectsToHit[i].GetComponent<Enemy>() != null)
    {
    objectsToHit[i].GetComponent<Enemy>().EnemyHit(damage);
    }
    }
    }
    
    void SlashEffectAngle(GameObject _slashEffect, int _effectAngle, Transform _attackTransform)
    {
    _slashEffect = Instantiate(_slashEffect, _attackTransform);
    _slashEffect.transform.eulerAngles = new Vector3(0, 0, _effectAngle);
    _slashEffect.transform.localScale = new Vector2(transform.localScale.x, transform.localScale.y);
    }
    
    public bool Grounded()
    {
    if (Physics2D.Raycast(groundCheckPoint.position, Vector2.down, groundCheckY, whatIsGround)
    || Physics2D.Raycast(groundCheckPoint.position + new Vector3(groundCheckX, 0, 0), Vector2.down, groundCheckY, whatIsGround)
    || Physics2D.Raycast(groundCheckPoint.position + new Vector3(-groundCheckX, 0, 0), Vector2.down, groundCheckY, whatIsGround))
    {
    return true;
    }
    else
    {
    return false;
    }
    }
    
    void Jump()
    {
    if (Input.GetButtonUp(“Jump”) && rb.velocity.y > 0)
    {
    rb.velocity = new Vector2(rb.velocity.x, 0);
    
    pState.jumping = false;
    }
    if (!pState.jumping)
    {
    if (jumpBufferCounter > 0 && coyoteTimeCounter > 0)
    {
    rb.velocity = new Vector3(rb.velocity.x, jumpForce);
    
    pState.jumping = true;
    }
    else if (!Grounded() && airJumpCounter < maxAirJumps && Input.GetButtonDown(“Jump”))
    {
    pState.jumping = true;
    
    airJumpCounter++;
    
    rb.velocity = new Vector3(rb.velocity.x, jumpForce);
    }
    }
    
    anim.SetBool(“Jumping”, !Grounded());
    }
    
    void UpdateJumpVariables()
    {
    if (Grounded())
    {
    pState.jumping = false;
    coyoteTimeCounter = coyoteTime;
    airJumpCounter = 0;
    }
    else
    {
    coyoteTimeCounter -= Time.deltaTime;
    }
    
    if (Input.GetButtonDown(“Jump”))
    {
    jumpBufferCounter = jumpBufferFrames;
    }
    else
    {
    jumpBufferCounter = jumpBufferCounter – Time.deltaTime * 10;
    }
    }
    }</code>
    #16188
    Pool ForReal
    Level 4
    Participant
    Helpful?
    Up
    0
    ::
    <code>using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class PlayerController : MonoBehaviour
    {
        [Header("Horizontal Movement Settings:")]
        [SerializeField] private float walkSpeed = 1;
        [Space(5)]
    
        [Header("Vertical Movement Settings")]
        [SerializeField] private float jumpForce = 45f;
        private float jumpBufferCounter;
        [SerializeField] private float jumpBufferFrames;
        private float coyoteTimeCounter = 0;
        [SerializeField] private float coyoteTime;
        private int airJumpCounter = 0;
        [SerializeField] private int maxAirJumps;
        [Space(5)]
    
        [Header("Ground Check Settings:")]
        [SerializeField] private Transform groundCheckPoint;
        [SerializeField] private float groundCheckY = 0.2f;
        [SerializeField] private float groundCheckX = 0.5f;
        [SerializeField] private LayerMask whatIsGround;
        [Space(5)]
    
        [Header("Dash Settings")]
        [SerializeField] private float dashSpeed;
        [SerializeField] private float dashTime;
        [SerializeField] private float dashCooldown;
        [SerializeField] GameObject dashEffect;
        [Space(5)]
    
        [Header("Attacking")]
        bool attack = false;
        float timeBetweenAttack, timeSinceAttack;
        [SerializeField] private Transform SideAttackTransform, UpAttackTransform, DownAttackTransform;
        [SerializeField] private Vector2 SideAttackArea, UpAttackArea, DownAttackArea;
        [SerializeField] private LayerMask AttackableLayer;
        [SerializeField] float damage;
        [SerializeField] GameObject slashEffect;
    
        PlayerStateList pState;
        private Rigidbody2D rb;
        private float xAxis,yAxis;
        private float gravity;
        Animator anim;
        private bool canDash = true;
        private bool dashed;
    
    
    
        public static PlayerController Instance;
    
        private void Awake()
        {
            if (Instance != null && Instance != this)
            {
                Destroy(gameObject);
            }
            else
            {
                Instance = this;
            }
        }
    
        // Start is called before the first frame update
        void Start()
        {
            pState = GetComponent<PlayerStateList>();
    
            rb = GetComponent<Rigidbody2D>();
    
            anim = GetComponent<Animator>();
    
            gravity = rb.gravityScale;
        }
    
        private void OnDrawGizmos()
        {
            Gizmos.color = Color.red;
            Gizmos.DrawWireCube(SideAttackTransform.position, SideAttackArea);
            Gizmos.DrawWireCube(UpAttackTransform.position, UpAttackArea);
            Gizmos.DrawWireCube(DownAttackTransform.position, DownAttackArea);
        }
    
        // Update is called once per frame
        void Update()
        {
            GetInputs();
            UpdateJumpVariables(); 
    
            if (pState.dashing) return; 
            Move();
            Jump();
            Flip();
            StartDash();
            Attack();
        }
    
        void GetInputs()
        {
            xAxis = Input.GetAxisRaw("Horizontal");
            yAxis = Input.GetAxisRaw("Vertical");
            attack = Input.GetMouseButtonDown(0);
        }
    
        void Flip()
        {
            if (xAxis < 0)
            {
                transform.localScale = new Vector2(-Mathf.Abs(transform.localScale.x), transform.localScale.y);
            }
            else if (xAxis > 0)
            {
                transform.localScale = new Vector2(Mathf.Abs(transform.localScale.x), transform.localScale.y);
            }
        }
    
        private void Move()
        {
            rb.velocity = new Vector2(walkSpeed * xAxis, rb.velocity.y);
            anim.SetBool("Walking", rb.velocity.x != 0 && Grounded());
        }
    
        void StartDash()
        {
            if(Input.GetButtonDown("Dash") && canDash && !dashed)
            {
                StartCoroutine(Dash());
                dashed = true;
            }
    
            if(Grounded())
            {
                dashed = false;
            }
        }
    
        IEnumerator Dash()
        {
            canDash = false;
            pState.dashing = true;
            anim.SetTrigger("Dashing");
            rb.gravityScale = 0;
            rb.velocity = new Vector2(transform.localScale.x * dashSpeed, 0);
            if (Grounded()) Instantiate(dashEffect, transform);
            yield return new WaitForSeconds(dashTime);
            rb.gravityScale = gravity;
            pState.dashing = false;
            yield return new WaitForSeconds(dashCooldown);
            canDash = true;
        }
    
        void Attack()
        {
            timeSinceAttack += Time.deltaTime;
            if(attack && timeSinceAttack >= timeBetweenAttack)
            {
                timeSinceAttack = 0;
                anim.SetTrigger("Attacking");
    
                if(yAxis == 0 || yAxis < 0 && Grounded())
                {
                    Hit(SideAttackTransform, SideAttackArea);
                    Instantiate(slashEffect, SideAttackTransform);
                }
                else if (yAxis > 0)
                {
                    Hit(UpAttackTransform, UpAttackArea);
                    SlashEffectAngle(slashEffect, 80, UpAttackTransform);
                }
                else if (yAxis < 0 && !Grounded())
                {
                    Hit(DownAttackTransform, DownAttackArea);
                    SlashEffectAngle(slashEffect, -90, DownAttackTransform);
                }
            }
        }
    
        void Hit(Transform _attackTransform, Vector2 _attackArea)
        {
            Collider2D[] objectsToHit = Physics2D.OverlapBoxAll(_attackTransform.position, _attackArea, 0, AttackableLayer);
    
            if(objectsToHit.Length > 0 )
            {
                Debug.Log("Hit");
            }
            for (int i = 0; i < objectsToHit.Length; i++)   
            {
                if (objectsToHit[i].GetComponent<Enemy>() != null)
                {
                    objectsToHit[i].GetComponent<Enemy>().EnemyHit(damage);
                }
            }
        }
    
        void SlashEffectAngle(GameObject _slashEffect, int _effectAngle, Transform _attackTransform)
        {
            _slashEffect = Instantiate(_slashEffect, _attackTransform);
            _slashEffect.transform.eulerAngles = new Vector3(0, 0, _effectAngle);
            _slashEffect.transform.localScale = new Vector2(transform.localScale.x, transform.localScale.y);
        }
    
        public bool Grounded()
        {
            if (Physics2D.Raycast(groundCheckPoint.position, Vector2.down, groundCheckY, whatIsGround)
                || Physics2D.Raycast(groundCheckPoint.position + new Vector3(groundCheckX, 0, 0), Vector2.down, groundCheckY, whatIsGround)
                || Physics2D.Raycast(groundCheckPoint.position + new Vector3(-groundCheckX, 0, 0), Vector2.down, groundCheckY, whatIsGround))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    
        void Jump()
        {
            if (Input.GetButtonUp("Jump") && rb.velocity.y > 0)
            {
                rb.velocity = new Vector2(rb.velocity.x, 0);
    
                pState.jumping = false;
            }
             if (!pState.jumping)
            {
                if (jumpBufferCounter > 0 && coyoteTimeCounter > 0)
                {
                    rb.velocity = new Vector3(rb.velocity.x, jumpForce);
    
                    pState.jumping = true;
                }
                else if (!Grounded() && airJumpCounter < maxAirJumps && Input.GetButtonDown("Jump"))
                {
                    pState.jumping = true;
    
                    airJumpCounter++;
    
                    rb.velocity = new Vector3(rb.velocity.x, jumpForce);
                }
            }
    
    
            anim.SetBool("Jumping", !Grounded());
        }
    
        void UpdateJumpVariables()
        {
            if (Grounded())
            {
                pState.jumping = false;
                coyoteTimeCounter = coyoteTime;
                airJumpCounter = 0;
            }
            else
            {
                coyoteTimeCounter -= Time.deltaTime;
            }
    
            if (Input.GetButtonDown("Jump"))
            {
                jumpBufferCounter = jumpBufferFrames;
            }
            else
            {
                jumpBufferCounter = jumpBufferCounter - Time.deltaTime * 10;
            }
        }
    }</code>
    #16189
    Pool ForReal
    Level 4
    Participant
    Helpful?
    Up
    0
    ::
    <code>using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class DestroyAfterAnimation : MonoBehaviour
    {
        // Start is called before the first frame update
        void Start()
        {
            Destroy(gameObject, GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).length);
        }
    }
    </code>
    #16192
    Chloe Lim
    Level 10
    Moderator
    Helpful?
    Up
    0
    ::

    Could you send a screenshot of your slash animation timeline?

    #16193
    Pool ForReal
    Level 4
    Participant
    #16199
    Pool ForReal
    Level 4
    Participant
    Helpful?
    Up
    0
    ::

    like this ?

    View post on imgur.com
    #16200
    Chloe Lim
    Level 10
    Moderator
    Helpful?
    Up
    0
    ::

    Sorry for the delayed reply, when you made the slash effect into a prefab, did you use the slash prefab from the project or a slash effect gameobject found in the hierachy as reference for the playercontroller? Click on the serialized gameobject variable in the playercontroller script in the inspector and see where the slasheffect is sourced from, and send a screenshot

    #16204
    Pool ForReal
    Level 4
    Participant
    Helpful?
    Up
    0
    ::

    i think its found in hierachy and same as with blood spurt

    View post on imgur.com
    #16205
    Chloe Lim
    Level 10
    Moderator
    Helpful?
    Up
    0
    ::

    Oh, you have to make prefabs of each instantiated object and delete them from the hierachy, at the start they should not be present in the scene at all, they should be referenced from the project such that the original prefab will not be destroyed, basically the process should be like this

    1. Make a gameobject a prefab by dragging it in the project window
    2. Delete the gameobject present in the hierarchy
    3. Make sure the referenced gameobject in the playercontroller script is the one present in the project window
    #16206
    Pool ForReal
    Level 4
    Participant
    Helpful?
    Up
    0
    ::

    so i also delete dash effect,blood spurt from hierarrcy?

Viewing 15 posts - 1 through 15 (of 16 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: