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 shortyzsly · May 27, 2013 at 08:32 PM · objectspawningdisappearhorror

Make a game object disappear when your camera looks at it.

I'm creating a short horror game in which a mysterious creepy woman slowly follows you, but only when your not watching. when you turn around. I want to be able to see her disappearing. To create the "wtf omg thats creepy" effect. I would also be implementing random spawning as the level is a dark, danky skyscraper with about 7 floors. and the elevators broke so you must use the stairs. She is already following me. So i wanna add to the AI :)

Comment
Add comment · Show 3
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 shortyzsly · Nov 29, 2013 at 09:47 PM 0
Share

Nah man i keep getting a parsing error on the first line.

I usually use js not too familiar with csharp.

avatar image NDLP · Feb 17, 2014 at 05:48 PM 0
Share

Hi

I am trying to do something similar - I want the player to see an object in their peripheral vision and when they turn toward it - and object is now in center of the camera - the renderer is turned off and the object now spawns in another area of the screen. I would like this to be $$anonymous$$imally 3D but don't want to use triggers - just center of view. Thoughts?

avatar image robertbu · Feb 17, 2014 at 05:50 PM 0
Share

@NDLP - Please open this as a new question. Don't ask questions as 'Answers' to existing questions. There is a simple approach to solve your problem.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hiddenspring81 · May 27, 2013 at 09:35 PM

To make an object disappear when they become visible, use the OnBecameVisible event. Create a new script, and add it to your "ghost" character in your scene. Here's some sample code to get you started,

 public InvisibleWhenSeen : MonoBehaviour
 {
   const float ANIMATE_SPEED = 0.1f;
 
   void OnBecameVisible ()
   {
     StopCoroutine("ToggleVisibility");
     StartCoroutine("ToggleVisibility", true);
   }
 
   void OnBecameInvisible ()
   {
     StopCoroutine("ToggleVisibility");
     StartCoroutine("ToggleVisibility", false);
   }
 
   IEnumerator ToggleVisibility (bool visible)
   {
     // Figure the desired alpha amount
     float desiredAlpha = visible ? 1.0f : 0.0f;
     // Find all the renderers attached to the object
     var renderers = GetComponentsInChildren<Renderer>(true);
     if (renderers.Length == 0)
       yield break;
     
     // Find out starting alpha amount
     float startingAlpha = renderers[0].material.color.alpha;
     // Track how long the animation has been playing
     float totalTime = 0.0f;
     // Loop until we reach the desired alpha amount
     while (renderers[0].material.color.alpha != desiredAlpha)
     {
       // Update the alpha amount for each renderer
       foreach (var renderer in renderers)
       {
         var color = renderer.material.color;
         renderer.material.color = new Color(color.r, color.g, color.b, Mathf.Lerp(startingAlpha, desiredAlpha, totalTime * ANIMATE_SPEED));
       }
       // Pause momentarily, and then resume the animation
       yield return null;
       totalTime += Time.deltaTime;
     }
   }
 }

The code hasn't been tested, but it should be enough to get you started.

Comment
Add comment · 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

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

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Spawning an object in the direction of a mouse click? 1 Answer

Spawn objects (Instantiate) behind hierarchy 1 Answer

Having camera attack upon spawning player? 1 Answer

enemy spawning when dead 1 Answer


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