Pergunta

I am currently creating a joystick and therefore I want to replace the Get Axis method.

Here is my code

function UpdateSmoothedMovementDirection () { 
var h = TouchController.GetAxisRaw("Horizontal");

But Unity gives me this error :

An instance of type 'TouchController' is required to access non static member 'GetAxisRaw'.

How can I call an instance ?

Foi útil?

Solução

Add public variable of type TouchController to your script. Then add game object with TouchController script to your scene. If your script is derived from MonoBehaviour, in Hierarchy tab in Unity Editor drag and drop game object with TouchController onto your variable.

If your script is not a MonoBehaviour script, than you'll have to set this variable manually from some other MonoBehaviour script.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top