- Home /
Changing the sliding door script in Angry Bots to open at a button press.
Hello, I'm very new to Unity and have a quick question to ask. I am making a level for a class I am taking at college that requires me to make a level using the assets from Angry Bots. The problem I have is that I have 0 scripting experience and need to change the sliding door to open at a button press rather than a proximity trigger. Here is what the code looks like now:
#pragma strict
public var enterSignals : SignalSender;
public var exitSignals : SignalSender;
public var objects : System.Collections.Generic.List.<GameObject>;
function Awake () {
objects = new System.Collections.Generic.List.<GameObject> ();
enabled = false;
}
function OnTriggerEnter (other : Collider) {
if (other.isTrigger)
return;
var wasEmpty : boolean = (objects.Count == 0);
objects.Add (other.gameObject);
if (wasEmpty) {
enterSignals.SendSignals (this);
enabled = true;
}
}
function OnTriggerExit (other : Collider) {
if (other.isTrigger)
return;
if (objects.Contains (other.gameObject))
objects.Remove (other.gameObject);
if (objects.Count == 0) {
exitSignals.SendSignals (this);
enabled = false;
}
}
Any help is greatly appreciated!
$$anonymous$$eep the trigger principle but ins$$anonymous$$d of automatically opening the door (I actually do not really see where it happens in what you posted...), then you just need to add an
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space))//opening section.
So the idea is: Am inside the trigger box? Yes. Then am I pressing the button? Yes. Open the door.
If the door opens , you are only missing the input part.
I really appreciate your help with this, but I have no idea where to put that in the code-like I said I have zero scripting experience.
I am sorry to say but you need to learn first. The only solution here is to give you the code but you wouldn't get anything out of it. If you do not know program$$anonymous$$g, you will never get out of the mud. Get any program$$anonymous$$g books, I would recommend to start with C as it is the first one, but you could skip and dive in C# right on. If you know program$$anonymous$$g but not in Unity then start some tutorials, the web is filled with them.
Your answer
Follow this Question
Related Questions
How to configure Gui Buttons and trigger2D correctly? 1 Answer
Button back not clickable after rotation animation 1 Answer
How To play sound with a keypress 2 Answers
How to make animations on button press. 2 Answers
Button Press and Hold Animations 0 Answers