`Joystick.input' is inaccessible due to its protection level
link textHi,
I am getting the below mentioned error and i don't know how to fix it. I am new to game development, I am following a tutorial. I got the error mentioned and don't know how to go from here.
Error:
Assets/Scripts/MyPlayer.cs(27,60): error CS0122: `Joystick.input' is inaccessible due to its protection level
Script I am using
My Player.cs
using System; using System.Collections; using System.Collections.Generic; using UnityEngine;
public class MyPlayer : MonoBehaviour { public float MoveSpeed = 3f; public float smoothRotationTime = 0.12f; public bool enableMobileInputs = false;
float currentVeclocity;
float currentSpeed;
float speedVelocity;
Transform cameraTransform;
public FixedJoystick joystick;
private void Start()
{
cameraTransform = Camera.main.transform;
}
void Update()
{
Vector2 input = Vector2.zero;
if (enableMobileInputs)
{
input = new Vector2(joystick.input.x, joystick.input.y);
}
else {
input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
}
Vector2 inputDir = input.normalized;
if (inputDir != Vector2.zero)
{
float rotation = Mathf.Atan2(inputDir.x, inputDir.y) * Mathf.Rad2Deg+ cameraTransform.eulerAngles.y;
transform.eulerAngles = Vector3.up * Mathf.SmoothDampAngle(transform.eulerAngles.y, rotation, ref currentVeclocity, smoothRotationTime);
}
float tragetSpeed = MoveSpeed * inputDir.magnitude;
currentSpeed = Mathf.SmoothDamp(currentSpeed, tragetSpeed, ref speedVelocity, 0.12f);
transform.Translate(transform.forward * currentSpeed * Time.deltaTime, Space.World);
}
}
I have the same error what do I do
Answer by nswbity · Jan 06 at 03:56 PM
in joystick.cs change private Vector2 input = Vector2.zero; to public Vector2 input = Vector2.zero; it will solve the problem
Your answer
Follow this Question
Related Questions
Getting Raw Input Data From Controller 0 Answers
Joystick for my game? 0 Answers
Playmaker MousePick with joystick. 0 Answers
How can I apply a position (and not a translation) to my camera related to an axis value 0 Answers
What is the key mapping for a Logitech Extreme 3D Pro joystick in Unity? 0 Answers