Hello! I’m very new to scripting and I’m currently trying to learn inputs. I’ve been watching various videos but have been stuck on getting an input to work. Here’s the line of code that won’t work:
void Update ()
{
if (Input.GetButtonDown (“TO”))
Debug.Log (“Test!”);
}
That’s basically all the script. I left out the class and the first couple lines at the beginning, and to me it feels as thought this script should work fine. I’ve gone into Edit and changed the Input settings for TO, and I have bound it to r, but it wouldn’t read out in the console. So I tried starting a new project and now I have a compiler error “Input does not contain a definition for GetButtonDown”.
I have tried every solution I can think of! I hope you guys can help me sort this out!
PS If there are any awesome scripting videos I should check out, lemme know!
don’t do this, you’re assuming the problem is in the snippet you’ve provided and not elsewhere in the script, whilst at the same time saying you have no idea why its not working. Give us the entire script… and use code tags http://forum.unity3d.com/threads/using-code-tags-properly.143875/
Okay my bad! I wasn’t aware of the tag! I will include everything in my script, including my double slashes (I was using them for notes, so feel free to comment on them and make adjustments if I need to).
using UnityEngine;
using System.Collections;
using System;
public class Input : MonoBehaviour {
//this function will use the method GetKey & GetButton
//which will check if the player has pressed the key you detail
//once they do, they will perfrom the action you specify
//GetKey will search for a specific key and that key only
//GetButton will search for a key that the user can specify in the console
// Update is called once per frame
void Update ()
{
if (Input.GetButtonDown ("TB"))
Debug.Log ("Have a party!");
}
The error about the non-existent method occurs because you’ve named your own class “Input”.
The Input class that you want to access belongs to the UnityEngine namespace, however, as your code belongs to your own class with that name, it will refer to that instead of using the UnityEngine.Input class.