hi there, i have been digging for a while and tried multiple suggestions from similar questions but nothing is working, as you will understand i am very new to this and probably my problem is that i dont know exacly how to ask my issue. so here it goes:
i have a bunch of floats in various gameobjects and i want to have all that variable floats in one single component. so i created an empty object and named Controls and made a script to call for the floats.
i then call for a script from other object and tried to access the float from that script in this Controls script.
bellow the script i wanna call in Control:
public class PlayerMovement : MonoBehaviour
public float Jump;
public float Turn;
void Update()
{
if (Input.GetKey("space"))
{
Rb.AddRelativeForce(0, Jump * Time.deltaTime, 0, ForceMode.VelocityChange);
}
if (Input.GetKey("e"))
{
transform.Rotate(0, Turn * Time.deltaTime, 0, (Space)ForceMode.VelocityChange);
}
if (Input.GetKey("q"))
{
transform.Rotate(0, -Turn * Time.deltaTime, 0, (Space)ForceMode.VelocityChange);
}
}
Bellow the Universal Control Script
public class Controls : MonoBehaviour
{
public GameObject Player;
private PlayerMovement PM;
public float jump = 1000f;
public float turn = 200f;
public void Call()
{
PM = Player.GetComponent<PlayerMovement>();
}
public void Control()
{
PM.Jump = jump;
PM.Turn = turn;
}
}
Clearly its not working as intended, but the idea would be to call multiple scripts and use all the variables as floats in this empty game object.
this would be only for development so i don’t care if its heavy its just for development faze then the variables would go to a settings menu or be fixed all together.
Thanks in advance i understand this might be straight forward but i didnt find the solution.