Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Infectedspleen · Jan 12, 2014 at 06:09 PM · movementcontroller

Player movement & Ouya input.

Hi there,

I'm having a bit of trouble with my player controller script. I'm trying to setup controls with the Ouya controller. I've correctly setup the jump function. But when I try to setup the movement I get errors. I'm very new the scripting and I can't seem to understand where I'm going wrong.

Here's my script.

 using UnityEngine;
 using System.Collections;
 
 /// <summary>
 /// A simple character input. Arrows to move, left SHIFT to run, SPACE to jump.
 /// </summary>
 public class SimpleCharacterInput : RaycastCharacterInput
 {
 
     /// <summary>
     /// IF true always run.
     /// </summary>
     public bool alwaysRun;
 
     /// <summary>
     /// If true dropping from a passthrough platform requires user to press down and then jump.
     /// </summary>
     public bool jumpAndDownForDrop;
 
     private int movingDirection;
 
     public bool continuousScan = true;
     public OuyaPlayer player = OuyaPlayer.P01;
 
     // Use this for initialization
     void Start () {
     
         OuyaInput.SetContinuousScanning(continuousScan);
         OuyaInput.UpdateControllers();
     }
 
 
     void Update ()
     {
         OuyaInput.UpdateControllers();
         
         if (Input.GetKey(KeyCode.R)) {
             Application.LoadLevel(0);
         }
         
         jumpButtonHeld = false;
         
         jumpButtonDown = false;
         
         dropFromPlatform = false;
         
         x = 0;
         
         y = 0;
         
         
         
         x = Input.GetAxis("Horizontal") || OuyaInput.GetAxis (OuyaAxis.LX, OuyaPlayer.P01);
         
         y = Input.GetAxis("Vertical") || OuyaInput.GetAxis (OuyaAxis.LY, OuyaPlayer.P01);
         
         // Force y to use discrete values
         
         if (y > 0) y = 1; 
         
         if (y < 0) y = -1;
         
         
         
         // Run
         
         if (alwaysRun || Input.GetButton("Run") || OuyaInput.GetAxis (OuyaAxis.RT, OuyaPlayer.P01)) {
             
             x *= 2;
             
         }
         
         if (y == -1 && !jumpAndDownForDrop) dropFromPlatform = true;
         
         if (Input.GetKey(KeyCode.Space) || OuyaInput.GetButtonDown (OuyaButton.U, OuyaPlayer.P01) || OuyaInput.GetButtonDown (OuyaButton.A, OuyaPlayer.P01) || OuyaInput.GetButtonDown (OuyaButton.O, OuyaPlayer.P01) || OuyaInput.GetButtonDown (OuyaButton.Y, OuyaPlayer.P01))  {
             jumpButtonHeld = true;
             if (Input.GetKeyDown(KeyCode.Space) || OuyaInput.GetButtonDown (OuyaButton.U, OuyaPlayer.P01) || OuyaInput.GetButtonDown (OuyaButton.A, OuyaPlayer.P01)) {
                 if (jumpAndDownForDrop && Input.GetKey("down")) {
                     dropFromPlatform = true;
                 } else {
                     jumpButtonDown = true;    
                 }
                 swimButtonDown = true;    
             } else {
                 jumpButtonDown = false;     
                 swimButtonDown = false;
             }
         } else {
             jumpButtonDown = false;
             swimButtonDown = false;
         }
     }
     
 }

And here are the three errors I get...

  1. CharacterInput.cs(53,27): error CS0019: Operator ||' cannot be applied to operands of type float' and float' 2. CharacterInput.cs(55,27): error CS0019: Operator ||' cannot be applied to operands of type float' and float'

  2. CharacterInput.cs(67,21): error CS0019: Operator ||' cannot be applied to operands of type bool' and `float

I used the same implementation on the jump function and that worked.

Any help or advice would be very grateful.

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 Infectedspleen · Jan 13, 2014 at 06:48 PM 0
Share

Can anyone help at all.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by tanoshimi · Jan 13, 2014 at 06:58 PM

Firstly,

  • || means "or".

  • The error message is complaining about lines 53, 55, and 67.

The problem is the same on all three lines so, to demonstrate, let's look at line 57:

  x = Input.GetAxis("Horizontal") || OuyaInput.GetAxis (OuyaAxis.LX, OuyaPlayer.P01);

Let's suppose that the input from Input.GetAxis("Horizontal") is 0.5, and the input from the OuyaInput.GetAxis (OuyaAxis.LX, OuyaPlayer.P01) is 1.0.

Then this line says "set the value of x to be 0.5 or 1.0". Do you see the problem?

Comment
Add comment · Show 1 · 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 Infectedspleen · Jan 13, 2014 at 07:14 PM 0
Share

Thank you for the reply. I will go back and look at the script.

It's not clear to me and I don't see the problem, but it's defiantly a starting point for some research.

Thank you.

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

19 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

Related Questions

Multiple Cars not working 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

What's the best alternative to Character Controller? 2 Answers

Player Controller Rotation Script Help 2 Answers

Player Controller moves automatically forward. cant stop. 1 Answer


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