So I have this script to open a gate with a button. But the gate should be able to open up with different buttons so I need more then 1.
How am I able to add a size for the amount buttons?
private var open : boolean = false;
//String is used for the animations from the gate and lever to open and close it
public var openAnimationString : String;
public var closeAnimationString : String;
public var leverOpenAnimationString : String;
public var leverCloseAnimationString : String;
public var buttonTransform : Transform;
public var distToOpen : float = 6;
private var playerTransform : Transform;
private var cameraTransform : Transform;
public var openSound : AudioClip;
public var closeSound : AudioClip;
function Awake () {
playerTransform = GameObject.FindWithTag("Player").transform;
cameraTransform = GameObject.FindWithTag("MainCamera").transform;
if(open)
animation.Play(openAnimationString);
animation.Play(leverOpenAnimationString);
}
function Update () {
var alreadyChecked : boolean = false;
if (Vector3.Distance(playerTransform.position,buttonTransform.position) <= distToOpen)
if (Input.GetKeyDown("e") && !animation.isPlaying)
{
if(open)
{
animation.Play(closeAnimationString);
animation.Play(leverCloseAnimationString);
open = false;
alreadyChecked = true;
if (closeSound)
audio.PlayOneShot(closeSound);
}
if (!open && !alreadyChecked)
{
animation.Play(openAnimationString);
animation.Play(leverOpenAnimationString);
open = true;
if (openSound)
audio.PlayOneShot(openSound);
}
}
}