Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Plz help Unity an C# with blend tree

A topic by QwaukStak created Jan 28, 2021 Views: 215 Replies: 4
Viewing posts 1 to 3
Submitted

I need help with this script:

public Animator anim;

public GameObject Projectile;

    void Update()
    {
        if (Input.GetAxisRaw("Horizontal") == 0)
        {
            if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow))
            {
                anim.SetFloat("Speed", 2f);
                Instantiate(Projectile, attackPos.position, Quaternion.identity);
                Invoke("Switch", .5f);
            }
        }
        else
        {
            anim.SetFloat("Speed", Input.GetAxisRaw("Horizontal"));
        }
    }
    void Switch()
    {
        anim.SetFloat("Speed", Input.GetAxisRaw("Horizontal"));
    }


This script does what I want but whenever I stop moving and have not pressed S or down arrow to attack I stay in the walk Animation forever until I attack again. Also I want the character to stop moving before it attacks(and it is a platformer if that matters)

Deleted post
Submitted

Thanks you have helped me alot this works better than my script.

Deleted post
Submitted

When I add the line to the script it makes the animation Janky but I'll try it one last time and see if that works if not I'll try to find another way. The set Floats sets the blend trees floats I created. -1 = walk 1 = walk and 0 = idle, its just the way I use the blend tree. Thanks for the help.