- Home /
Platform Control
Hello. I have written a simple platform script that works by replacing a tile with an identicle tile without a collider. Is there anyway to make it only work if you hit a trigger collider? The problem is that if I save this in my project and create multiple copies they will all follow the script at the same time. Please help.
var Platform1 : GameObject;
var Platform2 : GameObject;
function Start () {
Platform1.active = true;
Platform2.active = false;
}
function Update () {
if(Input.GetMouseButtonDown(1)){
Platform1.active = false;
Platform2.active = true;
}
if(Input.GetMouseButtonUp(1)){
Platform1.active = true;
Platform2.active = false;
}
}
Answer by Em3rgency · Jun 30, 2013 at 10:51 PM
I'm not exactly sure what you're trying to do. Would something like this work?
var Platform1 : GameObject;
var Platform2 : GameObject;
var controlActive : bool;
function Start ()
{
controlActive = false;
Platform1.active = true;
Platform2.active = false;
}
function Update ()
{
if(controlActive)
{
if(Input.GetMouseButtonDown(1))
{
Platform1.active = false;
Platform2.active = true;
}
if(Input.GetMouseButtonUp(1))
{
Platform1.active = true;
Platform2.active = false;
}
}
}
function onTriggerEnter(col : Collider)
{
controlActive = true;
}
function onTriggerExit(col : Collider)
{
controlActive = false;
}
Note: I normally code in c#, so there might be compiler errors here, sorry.
I will have to test this in a few hours. I am very very very sorry. I am very busy at the moment.
No sweat :) $$anonymous$$ake sure your collider is set to trigger.
Thank You very much. I'm Sorry it took such a long time to test the platforms. This is a very nice script you have written. :)
Quick question, when I enter the collider, The controlActive does not turn true so I can not fall through. (Is it suppose to turn true?)
In any other way the script is great.
Well, yes, it is supposed to turn true when you enter a trigger collider.