Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Endersky1 · Dec 24, 2015 at 08:56 AM · scripting problemgun scriptxboxcontroller

Why wont my script detect the input of my controller?

I am making a fps dependent on the xbox360 controller, when I was setting up the trigger to fire the gun I got this error Cannot implicitly convert type float' to bool' , if it helps when I was setting up the input the only things I did was change the name to FireGun, changed the type to Joystick Axis and changed the Axis to 9th axis (Joysticks) here is the script:

using UnityEngine; using System.Collections;

public class Shoot_Script : MonoBehaviour {

 public Rigidbody bulletPrefab;
 public Transform barrelEnd;
 
 void Start ()
 {
 }

 void Update ()
 {
     if(Input.GetAxis("FireGun")
     {
         Instantiate (bulletPrefab, barrelEnd.position, barrelEnd.rotation);
     }
     
 }

}

Also yes, I did check and it's the input not the script itself. With a mouse it works fine

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

· Add your reply
  • Sort: 
avatar image
0

Answer by GAZEREAPER · Dec 24, 2015 at 04:37 PM

you forgot another ")" after the unput line.

And you cant just ask if a float is true or false, the input.getaxis asks the AXIS, wich usualy is something in between negative 1 or positive 1. If you want to check a button press, you have to use Input.GetButtonDown("FireGun") OR Input.GetButton("FireGun") if you want it to keep checking if it is held down all the time.

But if you really need to use axis you could use: public Rigidbody bulletPrefab; public Transform barrelEnd;

  void Update ()
  {
      float fg = Input.GetAxis("FireGun");
      if(fg < -0.01)
      {
          Instantiate (bulletPrefab, barrelEnd.position, barrelEnd.rotation);
      }
      
  }

However this will give the same effect as Input.GetButton, because it will keep executing everyframe as long as the button is pressed.

Good luck.

Comment
Add comment · Show 3 · 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
avatar image Endersky1 · Dec 24, 2015 at 06:55 PM 0
Share

that was part of the problem but it still won't work I have a feeling that it's the way I set up the input manager here is a picture of it:alt text

inputmanager.png (38.6 kB)
avatar image GAZEREAPER Endersky1 · Dec 24, 2015 at 07:55 PM 0
Share

exactly what button are you trying to map? is it an axis or a button?

avatar image Endersky1 GAZEREAPER · Dec 24, 2015 at 08:22 PM 0
Share

I'm trying to map the left trigger on a xbox360 controller

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How would I add force/ burst fire to my gun? 2 Answers

How to change the damage my gun does? 1 Answer

How to add fireRate to my gun script? (Need Help) 1 Answer

My gun shoots while I'm reloading 2 Answers

Need help with burst fire script / adjusting the amount of damage my gun does. 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