I have a moving platform script which i have gained from doing a tutorial online and works fine but i would like it to move when the character touches the platform.
MovingPlatform Script:
#pragma strict
var Xpos : float;
var Ypos : float;
var max : boolean;
var Vert : boolean;
var maxAmount : float;
var step : float;
function Start () {
Xpos = transform.position.x;
Ypos = transform.position.y;
max = false;
}
function Update () {
//SET THE MAX
if(transform.position.y > Ypos + maxAmount){
max = true;
}
if(transform.position.y < Ypos){
max = false;
}
if(transform.position.x > Xpos + maxAmount){
max = true;
}
if(transform.position.x < Xpos){
max = false;
}
//MOVING THE PLATFORM
if (Vert){
if(!max){
transform.position.y += step;
} else {
transform.position.y -= step;
}
}
This is the trigger script:
//attach this script to your trigger
var Player : GameObject; //(First Person Controller as that is where the collider is)
var Script : MonoScript; //(PlatformMover)
function OnTriggerEnter(other : Collider) //Check if something has entered the trigger ( and declares this object in “other” )
{
if(other.collider.tag == Collider) //Checks if the Player is inside the trigger
{
Script = GetComponent(MonoScript);
Script.enabled = true; //enables PlatformMover.
}
This has been killing me for last week and unsure how to go about it. I know it will be a true or false but unsure on the scripting reference for character within the script.