• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed May 28, 2017 at 06:39 PM by jmelendezartist for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by jmelendezartist · May 28, 2017 at 03:16 PM · mobile2d-platformertouch controls

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.alt text

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);
     

 }



         
         


     

 

}

2017-05-28-023022.jpg (187.0 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
0
Best Answer

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");

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

124 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do you move 3D object by touch on mobile 0 Answers

Touch Controls 2d platformer. 0 Answers

Whats going wrong in my Scripts? 0 Answers

How do I stop reading the first touch when using TouchPhase.Moved 0 Answers

How to have UI Manager come up on collision? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges