Skip to content

How to read Keyboard input from C# script using nodes #6

@FlorianLance

Description

@FlorianLance

Thank you for the amazing support.
Below is my attempt to read the keyboard input from slot 5:

####################
// system
using System;
using System.Reflection;
using System.Collections.Generic;

// unity
using UnityEngine;

namespace Ex{


public class CS_move_cube : BaseCompiledCSharpComponent{

    CubeComponent Cube = null;
    // Ex component flow functions, uncomment to use
    // # once per loading
    public override bool initialize() {
        Cube = (CubeComponent)get("Cube");
        return true;
    }
 
    public override void update() {
        
        var CubeConfig = Cube.current_config();
        Vector3 CubePos = CubeConfig.get<Vector3>("position");
        float CubeHeight = CubePos.y;
        
        var idV = (IdAny)slot5;

        if(idV.id == 0){
            CubeHeight += 0.1f;
        }else if(idV.id == 1){
            CubeHeight -= 0.1f; 
        }
                   
        // # a TransformValue
        TransformValue trV = new TransformValue();
        trV.position = new Vector3(CubePos.x, CubeHeight, CubePos.z);
        trV.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
        trV.scale = Vector3.one;

        Cube.current_config().set_transform("transform", trV);

    }       
}

}

################

I get the following error:

[COMPILER] Compilation error CS0428 : "Cannot convert method group slot5' to non-delegate type Ex.IdAny'. Consider using parentheses to invoke the method" from file D:/Michel/ExVR/PPS_reaching/assets/CS_move_cube.cs at line 27 and column 25

################
The connections:

image

###############

An alternative would be the read directly the keyboard within the script. If this would be the preferred way, what is the correct way to "catch" the latest pressed key ? last_event() or send_infos_and_signals()

Originally posted by @makselro in #5 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions