Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Christopher Travis · Apr 15, 2011 at 01:30 AM · animationcollidertriggerproximity

Having a door dissapear once a key is collected

I have a door object in my maze, that has a mesh collider on it so you cant pass through it from the beginning, but i want to make it so that once you activate the trigger animation set up on a chest you will be able to get through the door once this event has happened. This is the code i have for the chest,

var displayMessage = false;

function OnTriggerEnter (Player : Collider) { animation.Play("Take 001"); displayMessage = true; yield WaitForSeconds(3); displayMessage = false; }

function OnGUI ( ) { if ( displayMessage ) { GUI.Label(new Rect(Screen.width /2.5, Screen.height / 2, 200, 200), "You received rusty key"); } }

Once that has happened i want it so that when you approach the door you can now get through it, also that this would be the end of the game so id want it to stop after you got through the door.

Thanks in advance for any help

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Kourosh · Apr 15, 2011 at 01:38 AM

You need to disable the collider attached to the door object. I don't what kinda door is that that you can walk through it tho lol. Anyway you can simply remove the collider:

Destroy(GetComponent(MeshCollider));

And use box collider cause mesh collider is more costly on the performance and it's not really necessary for an object like a door. It'll look something like this:

function OnTriggerEnter (Player : Collider) 
{
     var door:GameObject = GameObject.Find("door");
     Destroy(door.GetComponent(MeshCollider));
     animation.Play("Take 001");
     displayMessage = true;
     yield WaitForSeconds(3);
     displayMessage = false;
     FadeOut.fadeOut = true; //---> change the fadeOut var in FadeOut.js to start fading out.
}

About the game end. You should know what happens when your game is over. For turning the screen to black. You have two options:

put a black plain in front of a camera and make an alpha animation or simply use Lerp to turn the alpha from 0 to 1 over time.

Attach this script to the black plain and name the script "FadeOut.js":

var increment:float; static var fadeOut:boolean = false;

function Update(){ if(fadeOut){ renderer.material.color.a = Mathf.Lerp(0,1,increment); increment +=0.02; } }

Or you might wanna try iTween plugin. It's free and does that for you in only one line code.

Comment
Add comment · Show 9 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MC HALO · Apr 15, 2011 at 01:41 AM 0
Share

could not have said it easier my self :)

avatar image Christopher Travis · Apr 15, 2011 at 01:42 AM 0
Share

yeah i no lol, ive ran out of time to have it animate opening unfortunately bt this is the last step i need and i can be half happy then. ok thanks for this sorry to be a pain but what would that look like in code with reference to what i want. my door object is called "door", i dont understand the get component bit sorry, totally new to this.

avatar image Christopher Travis · Apr 15, 2011 at 01:44 AM 0
Share

sorry lol as in how do i make it only disable it after the chest animation has been triggered?

avatar image Kourosh · Apr 15, 2011 at 02:07 AM 0
Share

no no, sorry for confusing you. Just change your current script (chest) no need to attack anything to your door.

avatar image Christopher Travis · Apr 15, 2011 at 02:13 AM 0
Share

ok yeah i just realised it was the same $$anonymous$$us the get component addition i have it working thankyou, that was my misunderstanding. would u be able to explain that setting up an ending at all? i tried to download itween bt i cant read the file for some reason so gonna have to go with the other method. unfortunately i dont no wat u mean by the lerp to turn alpha from 0 to 1 sorry

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Animation not playing but trigger works 1 Answer

Help with setting up a trigger animation 1 Answer

Destroy trigger so animation only plays once. 1 Answer

How do you set up a trigger animation without going through the collider? 0 Answers

Trouble getting a trigger to activate an animation 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges