- Home /
UI button animation
Hey , can anyone help me with this problem I will explain the problem in the example : The player animation make a shot animation and stand with guns but I need to make the player to throw a bombs with a button with UI to make its animation I attached the button with play string and called like a bombs and set the animation of shooting with SetInteger and script it with integer 0,2 It worked but there is alight problem that the shot made by clicked mouse and the when I clicked mouse the shot animation starting and then bombs Ps : "I am beginner " and the game is "2d"
I think I might use with if "And operator " -->" && "when the button is not clicked but how ??
hey the problem was solved by IsPointerOverGameObject function
Answer by ShadySaberMohamed · Jun 10, 2019 at 02:42 PM
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class charanimation : MonoBehaviour { private Rigidbody2D reg; public Animator animvar; public Button Btn;
// Use this for initialization
void Start () {
animvar = GetComponent<Animator>();
}
// Update is called once per frame
public void Update () {
reg = GetComponent<Rigidbody2D> ();
if (Input.GetButtonDown("Fire1")) {
animvar.SetInteger ("AnimTrans", 2);
}
else {
animvar.SetInteger ("AnimTrans", 0);
}
}
}
hey the problem was solved by IsPointerOverGameObject function
Your answer
Follow this Question
Related Questions
Animation script help light problem 0 Answers
Animation not working when UI buttons are pressed 0 Answers
How to make a script for "jetpack" boost animation 1 Answer
Touch GUI texture to toogle animation 0 Answers
Button Animation Bug 1 Answer