- Home /
moving my wall up & down
So I am very new to the whole Idea of creating games and such. I have read most of the unity manual, but I am having a hard time understanding, and creating the script to make a wall move up and down using a collider. I have found a few tutorials that use doors as their example from imported models, but I can't find one to teach me the script for a wall. I want the first person controller to walk into the wall and the wall go down so you can pass through then have it go up after a few seconds. I understand collider (i think) I know how to make the animation which I called (WallUp), and another for "WallDown" within unity. My problem is getting the script rite. Every time I hit game to play I get errors. After many alterations, and many tutorials I did nothing but confuse myself. I know the script is simple, and I am a little embarrassed to ask for a script, or a direction to find scripts. Any help would be so helpful. I would post my script but I know it is so messed up that it would be pointless.
It's never pointless to post a script, no matter how messed up. You might learn the concepts behind the solution, rather than just copy-pasting someone else's fix! Also, 'tags' are used to categorise your post, so it will find similar posts, and appear on other related search results.
@$$anonymous$$arowi: Whoops, posted right after you(basically saying the same things you did).
Answer by Julio Cesar · Nov 11, 2010 at 02:43 PM
Hi,
I think what you need to do is very simple, i tried this one time and it worked:
You have your object wall, and you've animated this wall going up and going down right??
You'll have to use triggers (trigger is an event that ocurs when something happen or collide with it). First you'll need to create a new gameObject empty and place a box collider to it, place this gameObject with the same scale and position of your wall object and add this script to it:
/*=============================================
===============JAVASCRIPT======================
==============================================*/
var wallObject : GameObject; //instantiate you wall object here trough the inspector, just drag and drop your wall object in this variable on the inspector.
function OnTriggerEnter(hit : Collider){
//for this if you'll have to tag your player object as "Player" trough the inspector too.
//this if just check if it is your player that is entering in the trigger
if(hit.Tag == "Player"){
//this will make your wall go up
wallObject.animation.Play("wallUp"); //check the name of your animations
}
}
function OnTriggerExit(){
//here on this function when your player exit the area of the trigger it will play your animation making the wall going down;
wallObject.animation.Play("wallDown"); //check the name of your animation
}
/*===========================================
==============END OF THE SCRIPT==============
=============================================*/
I hope this should help!
Good Luck with your game!!
Answer by cmixco · Nov 07, 2010 at 03:47 AM
a simple fix would be using a collider as a trigger and use OnTriggerEnter(call a method to lower door)/OnTriggerExit(call a method to raise door) to make the door open/close or if the door is moving up/down. just make sure the door moves fast enough for the player to get through it.
Your answer
Follow this Question
Related Questions
Presure plate that triggers an animation 1 Answer
An odd iTween+RageSpline animation issue with trigger/collider! 1 Answer
Sliding door animation question. 3 Answers
How would I go about making an animation affected by this script? 1 Answer
code to play my animation on button press, but it is looping. What do I add to stop this? 1 Answer