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.
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:
A game object for your trigger area
A collider on the trigger area game object, set to be trigger
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.
Thank you for your quick reply! I'm going to look for some tutorials to create actions in these trigger area's.
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
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;
}
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.
Does it have to do that the ForwardSpeed is from a .cs file and the trigger event is a JS?
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.
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
Your answer
Follow this Question
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