Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by dhmaxhd · Sep 03, 2020 at 12:17 PM · transformunity 2dshootfirelocalscale

How do I make a player shoot right and left 2D platformer firing left and right, help!

How do I make a player shoot right and left 2D platformer firing left and right, help! Here is my script I'm making the game for android


using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityStandardAssets.CrossPlatformInput;

public class movo : MonoBehaviour { float bulletSpeed = 500f; public Animator anim; public Transform barrel; public Rigidbody2D bullet; private Rigidbody2D rb; private bool moveLeft; private bool moveRight; private float horizontalMove; public float speed = 5; public SpriteRenderer sp;

 private void Start()
 {
     anim = GetComponent<Animator>();
     rb = GetComponent<Rigidbody2D>();
     sp = GetComponent<SpriteRenderer>();
 
     moveLeft = false;
     moveRight = false;
 }
 
 public void PointerDownLeft()
 {
     anim.SetBool("run", true);
     moveLeft = true;
 }
 
 public void PointerUpLeft()
 {
     anim.SetBool("run", false);
     moveLeft = false;
 }
 
 public void PointerDownRight()
 {
     anim.SetBool("run", true);
     moveRight = true;
 }
 
 public void PointerUpRight()
 {
     anim.SetBool("run", false);
     moveRight = false;
 }
 
 void Update()
 {
     MovementPlayer();
     if (CrossPlatformInputManager.GetButtonDown ("Fire1"))
         Fire ();
 }
 
 void MovementPlayer()
 {
     if (moveLeft)
     {
         sp.flipX = true;
         horizontalMove = -speed;
     }
 
     else if (moveRight)
     {
         sp. flipX = false;
         horizontalMove = speed;
     }
 
     else
     {
         horizontalMove = 0;
     }
 }
 
 private void FixedUpdate()
 {
     rb.velocity = new Vector2(horizontalMove, rb.velocity.y);
 }

 void Fire()
 {
     var firedBullet = Instantiate (bullet, barrel.position, barrel.rotation);
     firedBullet.AddForce (barrel.up * bulletSpeed);
 }


and this code to Bullet

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class DestroyInTime : MonoBehaviour { [SerializeField] float destroyTime = 2f;

 void Start() {
     Destroy(gameObject, destroyTime);
  
 }

}

Comment
Add comment · Show 1
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
avatar image Captain_Pineapple · Sep 04, 2020 at 08:09 AM 0
Share

as i already posted below your last comment: Be more specific with your problem! if your description is less then 5 lines then it is probably not enough. Provide details: What exactly is not working? How do you see it is not working?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by N-8-D-e-v · Sep 03, 2020 at 12:41 PM

This should work perfectly, I don't see what's wrong with it

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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

181 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 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

Changing transform.localScale of a prefab in the script not working. Help pls! 1 Answer

scale based on position(help) 1 Answer

how do i stop automatic firing? 3 Answers

How to convert GameObject array to Transform array in C#? 2 Answers

Resize object forward instead of along the z axis 4 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