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 /
  • Help Room /
This question was closed Dec 02, 2017 at 08:54 AM by 1sd15 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by 1sd15 · Oct 25, 2017 at 01:47 PM · unity 5cameraupdateintenabled

InputKey on Update with INT Counter - Camera Switch - Not working properly.

The Problem:


So, when I Input a Key in the void update, it repeats the input multiple times on one press(I Think) and it repeats the addition of 1 to the INT multiple times as well. I have no idea why or if this is even the problem! I just wanted to make a simple camera switch script that would change the object enabled based on inputs like a flip-flop. :|
When I press the key in question, instead of going to the next script it bugs out the camera a bit as it spams the input. I think that is what is happening as when I print the counter, it goes wild through all of the counts and bugs the screen out a bit as it goes from Camera 1 to Camera 3, to Camera 2 randomly.
Anyway, I am sorry if that does not make much sense, it's very hard to explain this kind of problem as it only really appears on the unity side of things rather then on the coding side. Thanks for your help in advance! I have put below my code and a GIF of the problem, any feedback, or queries on my question is welcomed and I hope the way I have laid it out suits you. :)
Code:

 using UnityEngine;
 using System.Collections;
 
 public class CameraSwitch : MonoBehaviour {
 
     public GameObject FirstPerson;
     public GameObject ThirdPersonFixed;
     public GameObject ThirdPersonRotation;
     private int CKeyCounter = 0;
 
     void Update () {
 
         //Input
         if (Input.GetKey("c"))
         {
 
             //InputCounter
             CKeyCounter = CKeyCounter + 1;
 
             //ResetCounter
             if (CKeyCounter == 4)
             {
                 CKeyCounter = 1;
             }
 
             //Inputs
             if (CKeyCounter == 1)
             {
                 FirstPerson.SetActive(false);
                 ThirdPersonRotation.SetActive(true);
             }
 
             if (CKeyCounter == 2)
             {
                 ThirdPersonRotation.SetActive(false);
                 ThirdPersonFixed.SetActive(true);
             }
 
             if (CKeyCounter == 3)
             {
                 ThirdPersonFixed.SetActive(false);
                 FirstPerson.SetActive(true);
             }
 
             // Small Hierarchy Set:
             //
             // 1 = First Person
             // 2 = Third Person Fixed
             // 3 = Third Person Rotation
 
         }
 
         //TestingPrinter
         print(CKeyCounter);
         //VeryUseful
 
     }
 }


GIF Picture


https://gyazo.com/b7a48a421d283a47d0a8b13b3045a4f7

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
1
Best Answer

Answer by coolyer · Nov 01, 2017 at 11:23 PM

The problem is that you set Input.GetKey("c")) Change it to Input.GetKeyDown("c"))

To make this work you need to create a empty game object called "Manager" or somthing along the lines, then put the "CameraSwitch" script in the Manager Object you made. And it should work.

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

Follow this Question

Answers Answers and Comments

220 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Weird Rendering Unity5 1 Answer

Switching player controllers 0 Answers

Transforms update problem 0 Answers

question about unity version update 0 Answers

Hello.I use the Region Capture to create the coloring of augmented reality. 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