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’

  3. 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.

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?