Hey,
I want to make a falling platform that does all the dirty work for me.
So what i did before:
I created a platform(simple cube), on that platform i put a trigger.
Then i had to scripts, one on the platform itself to move it when the trigger was hit, one on the trigger with a bool for when its hit, to use in the platform script.
Now this is something that works fine until you want 10 or even 100 platforms
Aside from all the dirty work there is a problem. when i make 2 platforms with 2 triggers, using the same triggerscript(with the bool) Both platforms will fall down when i stand on one of them, cause they use the same script so the same bool. Thats not what i want. So apparently 2 objects using the same script cant act individually!
But you dont wanna make 100 scripts for 100 triggers, all doing the same thing! So how can you solve this problem?
Then to my goal, for solving this problem i started working on a single script to put on a platform that makes his own trigger (via code), so that every platform has its own trigger (and you dont have to do it yourself manually). But now i want to create a script in script to put on the trigger (made in script). So 1 script on a platform creates his own trigger and triggerscript to handle the action.
So every platform acts individually and can simply be copied.
Can this work? or is there a better way to avoid making seperate scripts for the same job on different platforms for them to act individually?
Thanks.
This is what i have so far:
var Gravity: float;
var time: float;
var FallingSound: AudioClip;
var SoundPlayed: boolean;
var OriginalPos: Vector3;
var OriginalPosTarget: Vector3;
var OriginalPosTrigger: Vector3;
var target : Transform;
private var controller : FallingPlatformTriggerScript;
private var Trigger: GameObject;
function Awake()
{
OriginalPos = transform.position;
OriginalPosTarget = target.position;
OriginalPosTrigger = transform.position;
OriginalPosTrigger.y += 1;
Trigger = GameObject.CreatePrimitive(PrimitiveType.Cube);
Trigger.renderer.enabled = true;
Trigger.collider.isTrigger = true;
Trigger.transform.position = OriginalPosTrigger;
Trigger.collider.bounds.size = transform.collider.bounds.size;
}
function Update()
{
if (target)
{
controller = target.GetComponent(FallingPlatformTriggerScript);
}
else{return;}
if(controller.IsHit == true)
{
time += Time.deltaTime;
if(!SoundPlayed)
{
audio.PlayOneShot(FallingSound);
SoundPlayed = true;
}
var Total = (0.5Gravity(time * time));
transform.Translate(Vector3.down * Total);
target.Translate(Vector3.down * Total);
Trigger.transform.Translate(Vector3.down * Total);
}
if(transform.position.y < -50)
{
Reset();
}
}
function Reset()
{
controller.IsHit = false;
time = 0;
transform.position = OriginalPos;
target.position = OriginalPosTarget;
Trigger.transform.position = OriginalPosTrigger;
SoundPlayed = false;
}