Problem is not reproducible or outdated
Problem with simple attack Attack ui Button
need some help,, i was make ui button attack, but it doesn't work, this my script,, :
using UnityEngine;
using System.Collections;
public class Attack : MonoBehaviour
{
private Animator animator;
// Use this for initialization
void Start ()
{
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update ()
{
animator.SetBool("Attack1", false);
}
void Attack ()
{
if (Input.GetKeyDown (KeyCode.Space)) //take action/button from keyboard
{
animator.SetBool ("Attack1", true); //can attack
}
}
public void Attack1 ()
{
{
Attack(); //use for ui button
}
}
Answer by Alec-Slayden · May 25, 2016 at 06:52 AM
More information as to what is wrong would be helpful, but there might be a few things going wrong here.
Firstly, since you are setting your attack parameter to false every Update, it will be set false immediately after it was set to true. This may be causing interruptions in the animation.
Secondly, Attack() is called from Attack1(), but nowhere else that I can see, so it will only be called if Attack1() is called, and therefore not by spacebar. I don't know why you have a nested set of brackets in that method, but I will assume there is purpose.
Thirdly, because you are looking for spacebar in the attack method, it will only be called if the spacebar was pressed down the exact same frame as you clicking the UI element that calls Attack1() ... assuming that is what it is for.
If none of those point towards the issue, it could be something wrong with your mecanim setup; for example, the transition to your attack animation may not involve the Attack1 parameter properly.
If you are attempting to listen to the keyboard every frame, you will need to check for it in update, and when it is down, then call Attack().
Attack() will then need the space bar check removed so that the public method Attack1() can cause the logic without the check.
However, I would strongly advise condensing it into one public method for simplicity unless you intend to have separate logic specifically for the UI implementation.
Follow this Question
Related Questions
How to make more combo attack,, 1 Answer
Problem with simple attack button,, 1 Answer
Problem with combo attack -1 Answers
how can i make simple combo attack,, 0 Answers