Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Kek_Kek · Apr 15, 2018 at 03:15 AM · isvisible

Render.isVisible help

I created a script which is turned on after an object is set active. When the object is set active you have a certain amount of time to find and look at the object or it will attack you. If you are able to look at the object in the given time, the script is disabled and another one is enabled to set the object active. I used a if(GetComponenet().isVisible) and added a debug logs to see if it works.

 {
 
     public MonoBehaviour othercomponent;
     private bool shown;
     RaycastHit hit;
     public float thedistance;
     public int speed;
     Coroutine co;
 
     // Use this for initialization
     void Start() {
         StartCoroutine(Startt());
         co = StartCoroutine(Startt());
     }
 
     IEnumerator Startt()
     {
         Showing();
         shown = true;
         yield return new WaitForSeconds(speed);
         shown = false;
         Attacking();
     }
 
     IEnumerator Startt2()
     {
         yield return new WaitForSeconds(speed);
         othercomponent.enabled = true;
         GetComponent<Shown>().enabled = false;
     }
 
     // Update is called once per frame
     void Showing()
     { 
 
 
         Debug.Log("Shown");
         if (GetComponent<Renderer>().isVisible)
         {
             Debug.Log("Visible");
             thedistance = hit.distance;
             StartCoroutine(Startt2());
             StopCoroutine(co);
         }
     }
 
     void Attacking()
     {
         if (shown == false)
         {
             Debug.Log("Attacck");
         }
     }
 
     void Update()
     {
      
     }
 
 
 }

The Problem is that the object does not become visible even when both scene and game view are looking at it. Am I using the isVisible wrong?

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 toddisarockstar · Apr 15, 2018 at 04:43 AM 0
Share

isVisible in my experience is not accurate enough to use for game play. It's more for rendering proficiency in large levels to limit sending mesh info to the video card and does have some inaccuracy.

depending on your game and how many objects you have... i would recommend using a very occasional general distance check. if you use square distance its much more proficient than unity's Vector3 distance. (just subtract start and finish vector points to see if the absoulutes are both smaller than your liking).

sounds like you could limit to every second or so with your checks.

once you know an object is within proximity you could compair your players forward axis to the angle between the player and object using something like this: [https://docs.unity3d.com/ScriptReference/Vector3.Angle.html][1]

do an occational raycast to the object to see if you have a hit (probobly from the top).

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by MarioSantoso · Apr 15, 2018 at 03:22 AM

You should use these to check whether an object is visible to a camera or not

         private void OnBecameVisible()
         {
             // your code here
         }
 
         private void OnBecameInvisible()
         {
             // your code here
         }
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

78 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 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 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 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 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 avatar image avatar image avatar image

Related Questions

half of "if" argument being ignored by Unity 1 Answer

How to use isVisible or OnBecameInvisible() to detect player offscreen 1 Answer

Cast a ray only against "isvisible" objects 1 Answer

Call Method before OnDestroy() 1 Answer

Can I do isVisible for a specific camera? 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