Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by NikkiH · Nov 14, 2015 at 04:05 PM · controlsareazone

How can I change the controls of a game in a certain area?

I want to create a game that plays with expectations. I currently have a level with a path, it is easy to walk a path but it can become challenging when in certain area's the controls are mirrored, the speed of the character suddenly changes or the entire screen will flip 180 degrees. I don't have much experience in Unity therefor I was hoping maybe someone here knows how to do this.

Thanks in advance.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Statement · Nov 14, 2015 at 04:17 PM

Create a trigger area. When the player enter or exit the trigger area, the trigger area does something.

The "something" it does, could be to rotate or flip the camera, mirror controls or change character speed.

To create a trigger that does one of these things you need three things:

  1. A game object for your trigger area

  2. A collider on the trigger area game object, set to be trigger

  3. A script on the trigger area game object that implements OnTriggerEnter/Stay/Exit

If the trigger can't be triggered by anything but the player, consider setting up collision layers or using tags to identify if the player entered the area. Once you know a player entered the area, either send a message or event to the player to modify input, or set a trigger/bool on an animator for your camera to make it rotate or flip the way you want.

Comment
Add comment · Show 6 · Share
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
avatar image NikkiH · Nov 14, 2015 at 04:26 PM 0
Share

Thank you for your quick reply! I'm going to look for some tutorials to create actions in these trigger area's.

avatar image NikkiH · Nov 14, 2015 at 05:01 PM 0
Share

Do you maybe know why this script is not working?

 function OnTriggerStay (other : Collider) {
      float ForwardSpeed = 25.0f;
 }

Can't I change a variable in code? I tried to test when someone enters the trigger the ForwardSpeed is 25 ins$$anonymous$$d of 8

avatar image Statement NikkiH · Nov 15, 2015 at 03:10 AM 0
Share

You likely want to set the speed of object entering the trigger.

 // This assumes that this is the code on the trigger, not on the player.
 function OnTriggerStay (other : Collider) 
 {
     // Access a script on the object entering the trigger
     // the script can be on the collider, or any of its parents.
     // A common setup is to have child colliders, and this ensures
     // that your script is accessed even if its on your root.
     // Replace "YourScriptName" with the name of your player script
     // that has "var ForwardSpeed : float;"
     var script = other.GetComponentInParent.<YourScriptName>();
     if (script)
         script.ForwardSpeed = 25.0f;
 }
avatar image Statement NikkiH · Nov 15, 2015 at 03:14 AM 0
Share
  function OnTriggerStay (other : Collider) {
       float ForwardSpeed = 25.0f;
  }

You're mixing JS and C# code in one file. That is not allowed. Also your variable assignment is local and temporary and won't have any effect. See my example above.

avatar image NikkiH · Nov 14, 2015 at 05:06 PM 0
Share

Does it have to do that the ForwardSpeed is from a .cs file and the trigger event is a JS?

avatar image Statement NikkiH · Nov 15, 2015 at 03:13 AM 0
Share

Try not to mix JS and CS. You'll run into some issues using types from one another.

You can write code that uses both, but you'll have to think about how to solve it. Assemblies can't have cyclic dependencies.

avatar image
0

Answer by NikkiH · Nov 15, 2015 at 12:42 PM

Thank you for your reply, I eventually managed to get it working in a different way.

http://answers.unity3d.com/questions/1098177/how-to-change-settings-ontrigger.html#answer-1098266

Comment
Add comment · Share
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

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

34 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Audio Zone, that covers a Square Area? 0 Answers

How can I count the number of objects touching a collider and then destroy them? 2 Answers

Balancing game 0 Answers

Android Touchpad - Registering touch on whole screen 1 Answer

IOS camera movement controls 0 Answers


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