Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Cuppylen · May 30, 2015 at 05:00 PM · scripting problemplatformerhow todisablingplatformercontroller

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges