The question is answered, right answer was accepted
mobile shooting animation not playing on pointerDown
I'm making a mobile game. 2D girl shooter side scroller. I'm using touch screen controls and on the shooting pointerDown on the mobile UI is not working. Any help would be awesome.
heres the code I'm working with. I've been stuck on this for a while. Any help will be Appreciated. public class playerController : MonoBehaviour { //movement variables public float speedX; public float jumpSpeedY;
public float delayBeforeDoubleJump;
bool facingRight, Jumping, isGrounded, canDoubleJump;
float speed;
Animator anim;
Rigidbody2D myRB;
float fireRate = 0.5f;
float nextFire = 0f;
AudioClip swordSwooshing;
Transform firePos;
public GameObject LeftBullet, RightBullet;
void Start () {
anim = GetComponent<Animator>();
myRB = GetComponent<Rigidbody2D> ();
facingRight = true;
firePos = transform.FindChild ("firePos");
}
void Update (){
MovePlayer (speed);
Flip ();
//left movement
if (Input.GetKeyDown (KeyCode.LeftArrow)) {
speed = -speedX;
}
if (Input.GetKeyUp (KeyCode.LeftArrow)) {
speed = 0;
}
///right movement
if (Input.GetKeyDown (KeyCode.RightArrow)) {
speed = speedX;
}
if (Input.GetKeyUp (KeyCode.RightArrow)) {
speed = 0;
}
///jump movement
if (Input.GetKeyDown (KeyCode.UpArrow) && isGrounded) {
Jump ();
}
///double jump movement
if (Input.GetKeyDown (KeyCode.UpArrow) && canDoubleJump ) {
Jump ();
}
if (Input.GetKeyDown(KeyCode.Space)) {
anim.SetInteger ("State", 4);
Fire ();
resetShoot ();
}
}
void MovePlayer(float playerSpeed){
if (playerSpeed < 0 && !Jumping || playerSpeed > 0 && !Jumping) {
anim.SetInteger ("State", 2);
}
if (playerSpeed == 0 && !Jumping) {
anim.SetInteger ("State", 0);
}
myRB.velocity = new Vector3 (speed, myRB.velocity.y, 0);
}
void Flip () {
if (speed > 0 && !facingRight || speed < 0 && facingRight) {
facingRight = !facingRight;
Vector3 temp = transform.localScale;
temp.x *= -1;
transform.localScale = temp;
}
}
void OnCollisionEnter2D(Collision2D other){
if (other.gameObject.tag == "Floor") {
isGrounded = true;
canDoubleJump = false;
Jumping = false;
anim.SetInteger ("State", 0);
}
}
public void WalkingLeft(){
speed = -speedX;
}
public void WalkingRight(){
speed = speedX;
}
public void StopMoving(){
speed = 0;
}
public void Jump(){
//single Jump
if (isGrounded) {
Jumping = true;
isGrounded = false;
myRB.AddForce (new Vector2 (myRB.velocity.x, jumpSpeedY));
anim.SetInteger ("State", 3);
Invoke ("EnableDoubleJump", delayBeforeDoubleJump);
}
//double Jump
if (canDoubleJump) {
canDoubleJump = false;
myRB.AddForce (new Vector2 (myRB.velocity.x, jumpSpeedY));
anim.SetInteger ("State", 3);
}
}
public void Shoot(){
Fire ();
anim.SetInteger ("State", 4);
}
public void resetShoot(){
anim.SetInteger ("State", 0);
}
void EnableDoubleJump(){
canDoubleJump = true;
}
void Fire(){
anim.SetInteger ("State", 4);
if(facingRight)
Instantiate (RightBullet, firePos .position, Quaternion.identity);
if(!facingRight)
Instantiate (LeftBullet, firePos .position, Quaternion.identity);
}
}
Answer by jmelendezartist · May 28, 2017 at 06:39 PM
//so i removed thisvvvvvvvv public void resetShoot(){ anim.SetInteger ("State", 0); } ///and replaced "anim.SetInteger ("State", 0);" ///with Animator purseHit; Animator anim; Animator anim = GetComponent(); anim.Play("purseHit");
Follow this Question
Related Questions
UI Button Double jump 0 Answers
How to get the touch controls to work properly? 0 Answers
Moving a ball left/right with buttons 0 Answers
How do you detect if a touch is hitting an object? 0 Answers
Touch Controls 2d platformer. 0 Answers