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 0_osmile0_o · Sep 15, 2014 at 08:33 PM · gameobjectappeardissapear

Materialize an object, then destroy it.

I need an object to appear as player walks into a trigger. So basicly I am asking for just one line of a script to make an object materialize in front of a player and then to be destroyed. Here is a reference to what I want to achieve.

 public var AnObject : GameObject;
 
 function OnTriggerEnter(other : Collider){
     if(other.gameObject.name == "Player"){
          ------------------------????
          yield WaitForSeconds(3);
          GameObject.Destroy(AnObject);
     }
 }
Comment
Add comment · Show 1
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 0_osmile0_o · Sep 15, 2014 at 08:42 PM 0
Share

Here is the script. Shows no errors. However doesn't work.

 #pragma strict
 
 public var AmbienceCrate : GameObject;
  
 function Awake (AmbienceCrate)
 {
     renderer.enabled = false;
 }
 
 function OnTriggerEnter(other : Collider){
     if(other.gameObject.name == "Player"){
          renderer.enabled = true;
          yield WaitForSeconds(3);
          GameObject.Destroy(AmbienceCrate);
     }
 }
 

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by VesuvianPrime · Sep 15, 2014 at 08:54 PM

The following should be an excellent read for you: http://docs.unity3d.com/Manual/InstantiatingPrefabs.html

Comment
Add comment · Show 5 · 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 0_osmile0_o · Sep 15, 2014 at 08:58 PM 0
Share

I sure will but it would be nice to get an answer as well as a direction in which to move. Thanks thou.

avatar image VesuvianPrime · Sep 16, 2014 at 11:30 AM 0
Share

Hey osmile

I didn't mean for the link to be dismissive. The documentation page gives some great tips and tricks that explain how to instantiate different types of objects in the scene.

Give a man a fish vs $$anonymous$$ch a man to fish, etc

The other guys are taking a different angle on the problem:

If we assume that your "materialize" object is already in the scene, you can hide it by simply disabling the renderer

alt text

You can also enable/disable components via code:

 public GameObject materializeObject;

 ...

 materializeObject.renderer.enabled = true;


avatar image 0_osmile0_o · Sep 16, 2014 at 04:50 PM 0
Share

I got it! Here is a working script! Thank you so much.

 public var AmbienceCrate : GameObject;
 
 function Start ()
 {
     AmbienceCrate.SetActive(false);
 }
 
 function OnTriggerEnter (Col : Collider)
 {
     if(Col.tag == "Player")
     {
          AmbienceCrate.SetActive(true);
          yield WaitForSeconds(3);
          GameObject.Destroy(AmbienceCrate);
     }
 }

avatar image VesuvianPrime · Sep 16, 2014 at 07:27 PM 0
Share

I'm glad you got it working. Just keep in $$anonymous$$d that you are disabling the entire GameObject, which may or may not be exactly what you want.

avatar image 0_osmile0_o · Sep 16, 2014 at 07:45 PM 0
Share

I'm pretty sure it's fine for me. I only need it to appear once and won't need it anymore.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

how to make an enemy appear then disappear. (if possible with audio) 1 Answer

GameObject can disappear 1 second after play, but still appear in scene window 1 Answer

Move another object 1 Answer

cannot see game objects on maximise on play 1 Answer

How to make an gameobject dissapear when player gets close to it 0 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