- Home /
How to Disable my player controller script, if I have many characters?
Hello! Good day to everyone. :)
WHAT I HAVE IN MY GAME:
I have a typical player controller script in my game (move, jump, attack).
Several characters to choose from before playing the actual game (maybe more than 10).
There’s a part in my game where i need to disable my player controller script so that he cannot move. (say: a trap that freezes you for seconds.)
MY PROBLEM:
How should I approach the disabling of the player controller script of my character if i have at least 10 different player controller script with different names, since each character has different skills (one has double jump, one has melee attack)?
WHAT I HAVE SO FAR:
I have 1 User Controller Script that is separate from my player controller script. (User Controller Script = my universal script exclusively for input)
My User Controller Script is a bit like this:
PlayerController playercontroller = GetComponent<PlayerController>();
void Update() {
If (Input.GetButtonDown.(“Jump”))
jump = true;
If (Input.GetButtonDown.(“Attack”))
attack = true;
………………
playercontroller.move (bool jump, bool attack,………………….);
}
*This is not my actual script.
I am thinking of just disabling my User Controller, since I only have 1 User Controller.
If so, then my new problem is: How can User Controller call player controller script that has at least 10 different names?
Shall I use:
UserController :MonoBehavior
If (GetComponent<PlayerController1>() == !null)
playercontroller = GetComponent<PlayerController1>();
else If (GetComponent<PlayerController2>() == !null)
playercontroller = GetComponent<PlayerController2>();
………………………..
playercontroller.move (bool jump, bool attack,………………….);
Does this work?
Also as I have said earlier i have at least 10 characters, which will make a very long list.
How can User Controller know which type of player controller to use in the first place?
AGAIN MY PROBLEMS ARE:
What is the most efficient way to disable my characters, when they approach a trap?
How can User Controller get player controller script of different names?
Can i make an empty public Script variable and drag my different player controllers in there, so User Controller can call that variable instead?
I am sorry, can’t convey my thoughts effectively.
Thank you very much
Your answer
Follow this Question
Related Questions
CharecterController.Move() ignores parents movement 0 Answers
Ground dash is like a teleport 0 Answers
Need some help with a platformer player script 0 Answers
2D 360 degress platformer example needed 0 Answers
What is the best way to detect collision?? Raycast2D, OnTriggerEnter2D, OnCollisionEnter2D 1 Answer